Page 1 of 1

Alternating color display

Posted: Wed Oct 16, 2002 10:40 am
by Reed
Hi,

I came across this script from evilwalrus

Code: Select all

<?
$result = mysql_query (SELECT * FROM table); 

if ($row = mysql_fetch_array($result)) { 

    for ($i = 0; i < count($row); $i++) { 
     
        // Set Table Row Color 
     
        if ($i % 2) { 
         
            echo "<tr bgcolor=B0C4DE>"; 
            } else { 
            echo "<tr bgcolor=FOF8FF>"; 
        } 

    // Now display our table cell info 
?> 

<td><? echo $rowї"whatever"]; ?></td> 
</tr> 

<? 
    } else { 
     
    echo "<tr bgcolor=B0C4DE><td>Sorry, no records were found!</td></tr>"; 
     
    } 
         
?>
I would like my data to be displayed in this format :

Code: Select all

<TABLE><TR><TD align=center>Title</TD></TR></TABLE>
<TABLE><TR><TD>Username: </TD></TR></TABLE>
<TABLE><TR><TD>Date: </TD></TR><TABLE>
<TABLE><TR><TD>Tel: </TD></TR></TABLE>
<TABLE><TR><TD>Website: </TD></TR></TABLE>
<TABLE><TR><TD>Price: </TD></TR></TABLE>
<TABLE<TR><TD>Email: </TD></TR></TABLE>
<TABLE><TR><TD align=center>Ad Description</TD></TR></TABLE>
How do i modify it to fit this portion:

Code: Select all

<td><? echo $rowї"whatever"]; ?></td> 
</tr>
Please advise.

Thanks :D

Posted: Wed Oct 16, 2002 10:00 pm
by SuperHuman
Well, that script that you are showing is inefficiant as it uses php modulus (%) and I would not reccomend using it for alot of returning rows. Your best bet would be to use the bitwise (&) operator for alternating row colors. Search the forum here, I am sure someone has posted an efficient way to alternate row colors......