Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I strongly recommend a templating library like <a href="http://twig.sensiolabs.org/">Twig</a> or <a href="https://github.com/bobthecow/mustache.php">Mustache</a>. However, the basics would be to use external PHP files as HTML, and use require. Here is a bit of a hacky example:</p> <pre><code>&lt;?php $comments = array(); while (mysqli_stmt_fetch($stmt)) { $comments[] = $stmt; } require 'comments.php'; </code></pre> <p>Then in <code>comments.php</code>:</p> <pre><code>&lt;?php foreach ($comments as $comment) : ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $comment['title'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $comment['date'] ?&gt;&lt;/td&gt; &lt;td align='center'&gt; &lt;a href='#'&gt; &lt;span class='view' title='View This Comment'&gt;&lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;td class='td_catchall' align='center'&gt; &lt;a href='#'&gt; &lt;span class='edit' title='Edit This Comment'&gt;&lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;td align='center'&gt; &lt;a href='#'&gt; &lt;span class='delete' title='Delete This Comment'&gt;&lt;/span&gt; &lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach ?&gt; </code></pre> <p>Here, I am adding each comment (or whatever it may be) to an array. Then, I include a file called <code>comments.php</code>. Your main file should be mostly PHP and should handle any logic, while <code>comments.php</code> should be mostly HTML and only use PHP for presentation (aka looping through an array and echoing out variables). </p> <p>Your required file has access to all the variables it would have access to if it were inline.</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