12-04-2010, 09:09 PM
|
#2 (permalink)
|
|
The Acquainted
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
|
Just count as you go and use an "if" to do something every 3rd, so am using the modulo operator to find out if it's the the 3rd, or is divisiable by 3 to echo the line with the class, or if it's false it echo's the line without the ADDCLASSHERE
PHP Code:
<?php $result = mysql_query("SELECT * FROM table WHERE publish='y' ORDER BY id DESC"); $counter = 1; while($row = mysql_fetch_array($result)) {
if ( $counter % 3 ){ echo "<div class=\"newsBlock ADDCLASSHERE\"><a href=\"article.php?article=" . $row['url'] . " \"><img src=\"http://www.talkphp.com/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>"; } else { echo "<div class=\"newsBlock\"><a href=\"article.php?article=" . $row['url'] . " \"><img src=\"http://www.talkphp.com/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>"; }
$counter = $counter + 1; // does $counter++ work ? } mysql_close($con); ?>
I think that should do what you want, someone will probably come along and show a simpler way
__________________
Thanks... Simon
Sex, Drugs & Linux Rules
|
|
|