Re: A Firefox colour problem???

Tim Roberts <[email protected]> Fri, 05 Aug 2005 10:05:58 -0700
Newsgroups gmane.comp.mozilla.devel.windows
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
Peter Butler wrote:
> 
>>>>>>>>BEGIN>>>>>>>>>>>>
> 
> 
>   while ($myrow = mysql_fetch_row($result))
>    {
>    $x++;
>    echo"<tr bgcolor=`#B8F8B6`><td><a
> href=\"estate_details.php?id=$myrow[0]\">$myrow[0]</a></td><td>$myrow[1]-$my
> row[2]</td><td>$myrow[4]</td><td><a
> href='mailto:$myrow[5]'>$myrow[5]</a></td></tr>" ;
>    $myrow = mysql_fetch_row($result);
>    echo"<tr bgcolor=`#F0F385`><td><a
> href=\"estate_details.php?id=$myrow[0]\">$myrow[0]</a></td><td>$myrow[1]-$my
> row[2]</td><td>$myrow[4]</td><td><a
> href='mailto:$myrow[5]'>$myrow[5]</a></td></tr>" ;
>    }
> 
>>>>>>>>END>>>>>>>>>>>>

This is unrelated to Mozilla, so I should be scolded for posting it 
here, but there is a problem with your code.  What happens if 
mysql_fetch_row in the while() statement fetches the very last row?  The 
call in the middle of the loop will fail.

You might consider this kind of algorithm instead:

     $colors = array('#B8F8B6','#F0F385');
     while( $myrow = mysql_fetch_row($result) )
     {
         echo "<tr bgcolor=$colors[0]><td>...";
         $colors = array($colors[1],$colors[0]);
     }
-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.