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
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]
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.