Jump to content


Photo

*SOLVED* Table property changes on the fly


  • Please log in to reply
2 replies to this topic

#1 titangf

titangf
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationColorado, USA

Posted 01 May 2006 - 03:53 PM

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...
<?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 }?>

Thanks for any help you can provide.
[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--][a href="http://www.csszengarden.com/" target="_blank"]css zen garden - beautiful design with the programmer in mind[/a][!--colorc--][/span][!--/colorc--]

[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--]Time is the invention of man to gauge what his achievements have been before he fades to dust.[!--colorc--][/span][!--/colorc--]

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 May 2006 - 04:17 PM

Some thing like this should do:
<?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++;
}?>


#3 titangf

titangf
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationColorado, USA

Posted 01 May 2006 - 04:26 PM

WOW.... Awesome! Thanks Wildteen. This works perfectly.
[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--][a href="http://www.csszengarden.com/" target="_blank"]css zen garden - beautiful design with the programmer in mind[/a][!--colorc--][/span][!--/colorc--]

[!--coloro:#3366FF--][span style="color:#3366FF"][!--/coloro--]Time is the invention of man to gauge what his achievements have been before he fades to dust.[!--colorc--][/span][!--/colorc--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users