hi guys, i want to have alternative row color in my table. this is the asp code and it's working fine. can anyone convert this to php for me? <table> <%Dim rowCount rowCount=0%> <%While not rs.EOF%> <tr bgcolor="<%if (rowCount mod 2)=0 then response.write("#ffffff") else response.write("#bcd8f5")%>> <td></td><td></td> </tr> <%rowCount = rowCount + 1%> <%rs.MoveNext%> <%Wend%> </table> HTML: thanks in advance.
<table> <?php $count = 0; while(NOT_SURE_WHAT_DATA_YOU_ARE_LOOPING_WITH): ?> <tr bgcolor="<?php if($count%2==0){ echo "ffffff"} else { echo"bcd8f5"};?>"> <td></td><td></td> </tr> <?php $count++; endwhile; ?> </table> PHP: ALso I took out the # before the color. I'm pretty sure you can't use #ffffff for the bgcolor property. You could alternately use style="background:#ffffff;"
Replace the 10 in "$rowcount < 10" with the number of rows you have <?php echo "<TABLE>"; For($rowcount = 0; $rowcount < 10; $rowcount++) { echo "<tr bgcolor=\"" . (($rowcount%2) == 0 ? "#FFFFFF" : "#BCDF85") . "\"><td></td></tr>"; } echo "</TABLE>"; ?> PHP:
<table> <?PHP $rowCount=0; while($sqlFetch=mysql_fetch_array($sqlQuery)) { ?><tr bgcolor="#<?PHP echo (rowCount%2==0?'ffffff'):"bcd8f5";?>"> <td></td><td></td> </tr> <?PHP $rowCount++; } ?> </table> PHP: