Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I improve this output to not include so much html?
    text
    copied!<p>I am fairly new to php and was wondering how I would go about improving this code. I know its not perfect but any constructive criticism is encouraged as I am trying to better myself in PHP. Please all I ask is that if you do answer with a way to improve it you expand upon the answer a little and let me know why it is better so I can get the full over view of the improvement.</p> <pre><code>public function displayArticle(){ //Check to see if we are getting the home page if($_GET['page'] == 'home'){ //Display the results formatted $content = "&lt;article class=\"igpPost\"&gt;"; $content .= "&lt;div class=\"igpPost-Divider\"&gt;&lt;/div&gt;"; $content .= "&lt;header&gt;"; $content .= "&lt;h3&gt;&lt;a href=\"#\"&gt;Ready Up – StarCraft 2, LoL, and Dota 2 pros head to DreamHack Summer&lt;/a&gt;&lt;/h3&gt;"; $content .= "&lt;div class=\"igpPost-AuthTime\"&gt;&lt;span&gt;Posted By: &lt;/span&gt;&lt;a href=\"#\"&gt;Cameron Lockhart&lt;/a&gt; &lt;span&gt;at 07:44PM on June 15, 2012&lt;/span&gt;&lt;/div&gt;"; $content .= "&lt;div class=\"igpPost-AuthTime\"&gt;&lt;span&gt;Tags: &lt;/span&gt;&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt; ,&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt; ,&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt; ,&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt; ,&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt; ,&lt;a href=\"#\"&gt;TAG HERE&lt;/a&gt;&lt;/div&gt;"; $content .= "&lt;div class=\"igpPost-Img\"&gt;&lt;img src=\"images/news/DreamHack-Summer-2012-logo.jpg\"/&gt;&lt;/div&gt;"; $content .= "&lt;/header&gt;"; $content .= "&lt;p&gt;Did last week’s MLG Spring Championship leave you thirsting for more eSports? Then DreamHack Summer 2012 has you covered. With well-attended tournaments for StarCraft 2, League of Legends, and Dota 2, DreamHack should keep you busy throughout the weekend and into the work-week. It starts tomorrow at 11 AM Eastern, and continues through Monday, with the StarCraft 2 Grand Final scheduled for 5:15 PM Eastern.&lt;/p&gt;"; $content .= "&lt;footer class=\"igpPost-Footer\"&gt;"; $content .= "&lt;div class=\"igpPost-ReadMore\"&gt;"; $content .= "&lt;h1&gt;&lt;a href=\"#\"&gt;Read More..&lt;/a&gt;&lt;/h1&gt;"; $content .= " &lt;/div&gt;"; $content .= "&lt;/footer&gt;"; $content .= "&lt;/article&gt;"; } //If it is not the home page and it is a single article if($_GET['article']){ //Display the article formatted } } </code></pre> <p>Also this is obviously not a completed script but looking at it it looks like to much for PHP. I read some tutorials and I think they sent me in the wrong direction with being correct and using good PHP.</p> <p>Update: I went through and tried to revise some of the code so that it gave a more descriptive overview:</p> <pre><code>$sql = "SELECT * FROM articles LIMIT $number"; $stmt = $pdo-&gt;query($sql); $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC); while($row = $stmt-&gt;fetch()){ //Display the results formatted $content = "&lt;article class=\"igpPost\"&gt;"; $content .= "&lt;div class=\"igpPost-Divider\"&gt;&lt;/div&gt;"; $content .= "&lt;header&gt;"; $content .= "&lt;h3&gt;&lt;a href=\"index.php?article=" . $row['id'] ."\"&gt;" . $row['title'] . "&lt;/h3&gt;"; $content .= "&lt;div class=\"igpPost-AuthTime\"&gt;&lt;span&gt;Posted By: &lt;/span&gt;&lt;a href=\"#\"&gt;" . $row['author'] . "&lt;/a&gt; &lt;span&gt;at " . formatDateTime($row['datetime']) . "&lt;/span&gt;&lt;/div&gt;"; $content .= "&lt;div class=\"igpPost-AuthTime\"&gt;&lt;span&gt;Tags: &lt;/span&gt;"; $content .= "&lt;div class=\"igpPost-Img\"&gt;&lt;img src=\"" . $row['imglocation'] ."\"/&gt;&lt;/div&gt;"; $content .= "&lt;/header&gt;"; $content .= "&lt;p&gt;" . $row['content'] . "&lt;/p&gt;"; $content .= "&lt;footer class=\"igpPost-Footer\"&gt;"; $content .= "&lt;div class=\"igpPost-ReadMore\"&gt;"; $content .= "&lt;h1&gt;&lt;a href=\"index.php?article=" . $row['id'] ."\"&gt;Read More..&lt;/a&gt;&lt;/h1&gt;"; $content .= " &lt;/div&gt;"; $content .= "&lt;/footer&gt;"; $content .= "&lt;/article&gt;"; echo $content; } </code></pre> <p>This is what im going for, im basically trying to separate the html from the PHP but insert the dynamic content in the places it needs to be. This is all within a class.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload