Jump to content

Question About HTML Tables


Recommended Posts

Guest CableGuy
Posted

Hi,

Quite funny that I do not know the answer to this, But I've seen a few sites that have roster's with 1 row being 1 color and another being another. While the roster is all automated, How i can i create it so it knows to make like the next row a certain color and the one after that another. For an example, Check below;

zxlaw5.jpg

  • Administrators
Posted

This is what I do

<style>
.row0 {background-color: #E0E0E0;}
.row1 {background-color: #ffffff;}
</style>

$class = 0;

foreach ($results as $result) 
{
echo '<tr class="row'.$class.'"><td>Your data</td></tr>';
$class = 1 - $class;
}

  • Administrators
Posted

I do:

<?php
$row_int = 0;
foreach($rows as $row)
{
$class = ($row_int++ % 2 == 0) ? 'row0' : 'row1';
echo '<tr class="'.$class.'">...</tr>';
}

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.

Loading...
×
×
  • Create New...