Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OP Asked for an example on the preferred way to write html for his example. Please don't treat this as an actual answer to his question:</p> <pre><code>&lt;?php while($row = $sth-&gt;fetch()): ?&gt; &lt;tr data-url="edit.php?id=&lt;?php echo $row['id']; ?&gt;"&gt; &lt;td&gt;&lt;?php echo $row['id'] ; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['firstName']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['lastName']; ?&gt;&lt;/h3&gt;&lt;td&gt; &lt;td&gt;&lt;?php echo $row['country']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['roomtype']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['roomnumber']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['checkin']; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $row['nights']; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endwhile; ?&gt; </code></pre> <p>Here's why this is preferred, though the opinion may vary from person to person: Maintainability: if code is easier to read, it is easier to maintain. when you echo html in php you are subject to escaping html, making it more cluttered to read...</p> <pre><code>&lt;?php echo "&lt;div class=\"someclass\"&gt;" . $content . "&lt;/div&gt;"; ?&gt; </code></pre> <p>effectively the same as:</p> <pre><code>&lt;?php echo '&lt;div class="someclass"&gt;' . $content . '&lt;/div&gt;'; ?&gt; </code></pre> <p>except that the second example (single quotes is string literal) does not require escaping the double quotes. However, in either case, anyone who has to maintain this would much prefer this:</p> <pre><code>&lt;div class="someclass"&gt;&lt;?php echo $content; ?&gt;&lt;/div&gt; </code></pre> <p>Because it is cleaner. Why? It just is. Also, many of the editors people use will highlight syntax differently for each language, so that in part makes it easier to read.</p> <p>There may be cases where echoing html in php makes some sense, but treat it very sparingly. Anyone that reads your code after you will appreciate it.</p> <p>Side note - you might want to change the html attribute "url" in your example to "data-url" as this is another convention you should use to keep people happy. Custom attributes are supported, but it is not a good idea to just make them up as you go. But if you have to, data- is the standard prefix for custom attributes.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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