Jump to content

Archived

This topic is now archived and is closed to further replies.

titangf

*SOLVED* Table property changes on the fly

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
WOW.... Awesome! Thanks Wildteen. This works perfectly.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.