[thelist] php array help...

Jay Greenspan jay at trans-city.com
Tue Mar 20 12:50:19 CST 2001


No shortage of ways to do this. You could use a variable to track row
number, then a trenary operator to determine the variable value.
Something like;

$i = 0;
while($row = mysql_fetch_array($results))
{
    $i++;
    $color = ( $i % 2) ?  "evenrow" : "oddrow";
    //rest of your stuff here.

}


-j


on 3/20/01 1:28 PM, Sowers, Matthew (CSC) at Sowers at VOLPE.DOT.GOV wrote:

> What'd I'd do is set a flag at the beginning of the PHP, and then do a logical
> choice on then when it comes time.
> 
> <<<CODE START>>>
> 
> // Here's the flag
> 
> $myFlag=0;
> if ($myrow = mysql_fetch_array($sql_result)) {
> do{
> 
> // Switch statement that will set class and reset the flag
> switch($myFlag){
> case 0:
> $color="evenrow";
> $myFlag=1;
> break;
> case 1:
> $color="oddrow";
> $myFlag=0;
> break;
> }





More information about the thelist mailing list