titangf Posted May 1, 2006 Share Posted May 1, 2006 Hello one and all. I am working on displaying a list of different items and I was noticing that after I had a long enough list that it becomes harder and harder to read. I was wanting to know if there was some type of function or if statment that would help alter the table's background so that it would alternate between two different colors (lets just say a light gray and white for now, I'm just playing around with the idea). I guess i'm trying to figure out how to do a check for every other list property being fed back to the html page and altering the table background accordingly.Here's what I have...[code]<?php while ($row_property = mysql_fetch_assoc($property)) {?> <tr> <td><?php echo $row_property['P_ID']; ?></td> <td><a href="property_details.php?P_ID=<?php echo $row_property['P_ID']; ?>"><?php echo $row_property['P_address']; ?></a></td> <td><?php echo $row_property['P_type']; ?></td> <td>$ <?php echo number_format($row_property['P_price'],0); ?></td> </tr> <?php }?>[/code]Thanks for any help you can provide. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 1, 2006 Share Posted May 1, 2006 Some thing like this should do:[code]<?php $i = 0;while ($row_property = mysql_fetch_assoc($property)) { $bg = ($i%2) ? "E1E1E1" : "FFFFFF"; ?> <tr style="background-color: #<?php echo $bg; ?>"> <td><?php echo $row_property['P_ID']; ?></td> <td><a href="property_details.php?P_ID=<?php echo $row_property['P_ID']; ?>"><?php echo $row_property['P_address']; ?></a></td> <td><?php echo $row_property['P_type']; ?></td> <td>$ <?php echo number_format($row_property['P_price'],0); ?></td> </tr><?php $i++;}?>[/code] Quote Link to comment Share on other sites More sharing options...
titangf Posted May 1, 2006 Author Share Posted May 1, 2006 WOW.... Awesome! Thanks Wildteen. This works perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.