View Single Post
Old 12-06-2010, 09:37 PM   #3 (permalink)
wGEric
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

Here is a way that makes it so that you don't have to have two lines of the same HTML. Makes it easier to maintain. maeltar's code is correct though and will work although it looks like the conditions might be backwards.

PHP Code:
<?php
    $result 
mysql_query("SELECT * FROM table WHERE publish='y' ORDER BY id DESC");
    
    
$counter 0;
    while(
$row mysql_fetch_array($result))            
    {
        
$class = ($counter == 0) ? 'ADDCLASSHERE' '';
        echo 
"<div class=\"newsBlock {$class}\"><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>&raquo;</span></a></div>";

        
$counter += 1;
        
// These all do about the same thing
        // $counter = $counter + 1;
        
        // make sure you know the difference between these two before using them
        // you might have unexpected results because the majority of
        // the time people want ++$var instead of $var++ but the use $var++
        // $counter++;
        // ++$counter;
    
}
?>
__________________
Eric
wGEric is offline  
Reply With Quote