On my website you can post a comment, but I am unsure how to style them using CSS. I remember reading something about using ul and li tags but I can't figure it out. I want each individual comment to have a border, background color, etc. Here is the PHP:
$query = "SELECT * FROM catharsis";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();
echo "<h4>开发者_C百科<center>Let it out.</center></h4>";
$i = 0;
while ($i < $num) {
$name = mysql_result($result,$num - $i,"message");
echo "$name<br>";
$i++;
}
What I'm trying to figure out is how to code this so that I can give a class to the echo "$name<br>";
and therefore style my comments with CSS.
Do:
echo '<ul class="comments">';
for($i = 0; $i < $num; $i++) {
$name = mysql_result($result,$num - $i,"message");
echo "<li>$name</li>";
}
echo '</ul>';
Then you can style it with this CSS:
ul.comments li {
// style goes here
}
You'll probably want to re-style ul.comments
too, since I doubt you want the default.
Alternately, you could do just <ul>
and make each <li>
into <li class="comment">
you would need to style both the <UL>
and <LI>
elements in CSS. When you echo them out, you would start with an unordered (bullet) list <UL>
and each new comment would be
<LI>My nifty comment</LI>
. You can style the UL so that it has no bullets using
list-style-type: none;
精彩评论