12-04-2010, 02:42 AM
|
#1 (permalink)
|
|
The Visitor
Join Date: Dec 2010
Posts: 1
Thanks: 1
|
Adding a [CSS] class every 3rd result
Hello all, new to PHP so please, bare with me.
I'm trying to add a class to every third result of a mySQL query. I've tried to figure it out but have had no luck.
PHP Code:
<?php
$result = mysql_query("SELECT * FROM table WHERE publish='y' ORDER BY id DESC");
while($row = mysql_fetch_array($result))
{
echo "<div class=\"newsBlock ADDCLASSHERE\"><a href=\"article.php?article=" . $row['url'] . " \"><img src=\"images//" . $row['image'] . "\" width=\"198\" height=\"106\"></a><h2>" . $row['title'] . "</h2><div class=\"date\">" . $row['date'] . "</div><p>" . $row['teaser_copy'] . "</p><a href=\"article.php?article=" . $row['url'] . "\" class=\"link\">" . $row['teaser_link'] . " <span>»</span></a></div>"; mysql_close($con);
}
?>
I've added 'ADDCLASSHERE' where I'd like to add the additional class. If it's not the third result no class is required.
Any help or guidance would be greatly appreciated.
Thanks in advance.
|
|
|
|