I created a comment system for my site, and I need a good way to see the end of the previous comment and start of the next one. To do that , I tought I'd place each row into two different divs that have slightly different background tone. Get it? Like this:
Row 1
row 2
row 3
etc..
$db
is database connection$query = $db->query("SELECT * FROM comments WHERE post_id='$id'");
while($row = $query->fetch_object()):
echo "<h5>".$row->name."</h5><br>";
$strip_comment = strip_tags($row->comment);
$strip_comment_slashes = stripslashes($strip_comment);
echo "<blockquote>".$strip_comment_slashes."</blockquote>";
You don't have to change your rendered markup for this, you can style every other element with CSS. That way the markup remains as just markup and not styling.
So if your markup is something like this:
<div id="container">
<div>content 1</div>
<div>content 2</div>
<div>content 3</div>
<div>content 4</div>
<div>content 5</div>
<div>content 6</div>
</div>
Then you can style every other child div
:
div#container div:nth-child(odd)
{
background-color: grey;
}
Uss the majical powers of CSS:
#comments tr:nth-child(odd){
background-color:#fff;
};
#comments tr:nth-child(even){
background-color:#ccc;
};
More resources: