Jump to content

*SOLVED* Table property changes on the fly


titangf

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.