Jump to content

Differn't class every 2nd table


Mr.x

Recommended Posts

Hey Everyone,
I'm just working on a small project for my school and am having some problems.

Basically my script is taking the information from a database and putting it into a table. There are alot of results so to help the users eyes, every 2nd table is a differn't color, for ex.
Row 1 - class="one" (in the CSS class one is a light grey)
Row 2 - class="two" (in the CSS class two is a light tan)
Row 3 - class="one"
Row 4 - class="two"
Row 5 - class="one"

<?
$studentid = mysql_query ("SELECT * FROM studentid WHERE category = '".$category."'");

echo "<table width='100%' border='0' cellpadding='5'>";

$row = mysql_fetch_assoc($studentid);

then at this point it would have to set either class one or two ex.
echo "<tr>
<td class='one' style='font-size: 9'><strong>".$row["studentid"]."</strong></td>
</tr>";

Any help would be greatly appreciated.
Link to comment
https://forums.phpfreaks.com/topic/6358-differnt-class-every-2nd-table/
Share on other sites

Something like this

[code]$studentid = mysql_query ("SELECT * FROM studentid WHERE category = '".$category."'");

echo "<table width='100%' border='0' cellpadding='5'>";

$count = 0;

while ($row = mysql_fetch_assoc($studentid)) {

    $class = ($count++ % 2) ? 'one' : 'two';

    echo "<tr>
      <td class='$class' style='font-size: 9'><strong>".$row["studentid"]."</strong></td>
      </tr>";
}
echo '</table>';[/code]

Archived

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

×
×
  • 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.