How would I write this so I'm only using one echo?
echo "<div class='post'>";
echo $row['title'];
echo "</div>";
I'm using an array to echo out a table's values but it would be a lot easier on the eyes if I could combine these into one echo statement. However, when I try to the page goes blank.
Enclose the array reference in brackets:
echo "<div class='post'{$row['title']}</div>";
echo "<div class=\"post\">{$row['title']}</div>";
echo '<div class="post">' . $row['title'] . '</div>';
The .
operator concatenates strings. Also, I believe HTML wants you to use double quotes for class="post"
(although perhaps it doesn't care?).
<?php
echo "<div class='post'".$row['title']."</div>";
?>
you forgot to close the div
> echo "<div class='post'"; should be
> echo "<div class='post'>";
Other ways of doing the same thing:
echo '<div class="post">'.$row['title'].'</div>';
echo sprintf('<div class="post">%s</div>', $row['title']);
<div class="post"><?php echo $row['title'] ?></div>