Results 1 to 6 of 6

Thread: PHP TR Color Help

  1. #1
    Join Date
    Nov 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PHP TR Color Help

    I am trying to alternate the TR color, can someone take a look and write something I can use to alternate the TR color. I have tried everything, no luck.

    Here is my query:

    $query = "select * from tl_tourny ORDER BY sdate ASC";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){

    $id = $row['id'];
    $name = $row['name'];
    $games = $row['games'];
    $location = $row['location'];
    $cost = $row['cost'];
    $sdate = $row['sdate'];
    $edate = $row['edate'];
    $age = $row['age'];
    $age2 = $row['age2'];
    ?>
    <tr>
    <td class="tournytextlite"><?php echo $sdate; ?></td>
    <td class="tournytextlite"><?php echo $edate; ?></td>
    <td class="tournytextlite"><?php echo $location; ?></td>
    <td class="tournytextlite"><a href="details.php?id=<?php echo $id; ?>"><?php echo $name; ?></a></td>
    <td class="tournytextlite"><?php echo $age; ?>&nbsp;&nbsp;<?php echo $age2; ?></td>
    <td class="tournytextlite">$<?php echo $cost; ?></td>
    <td class="tournytextlite"><?php echo $games; ?></td>
    <td class="tournytextlite"><a href="tournament_reg<?php echo $age; ?>.php">Register</a></td>
    </tr><?php } ?>

  2. #2
    Join Date
    Feb 2005
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    1. Do you want a random color?
    2. Where is your css file? If you want to create a different color, which will not change, you could easily do this: <tr class = "whatever"> and then in your css file put...

    .whatever {
    background: HEX/COLOR;
    }

  3. #3
    Join Date
    Nov 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No, I actually need it to alternate TR colors each time the DB generates a new entry. Two different colors alternating TR's.

  4. #4
    Join Date
    Feb 2005
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    $number = 0;
    $query = "select * from tl_tourny ORDER BY sdate ASC";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){

    $id = $row['id'];
    $name = $row['name'];
    $games = $row['games'];
    $location = $row['location'];
    $cost = $row['cost'];
    $sdate = $row['sdate'];
    $edate = $row['edate'];
    $age = $row['age'];
    $age2 = $row['age2'];
    $number++;
    if($number & 1) $bgColor = 'color1';
    else $bgColor = 'color2';

    ?>
    <tr style = "background: <?php echo $bgColor; ?>;">
    <td class="tournytextlite"><?php echo $sdate; ?></td>
    <td class="tournytextlite"><?php echo $edate; ?></td>
    <td class="tournytextlite"><?php echo $location; ?></td>
    <td class="tournytextlite"><a href="details.php?id=<?php echo $id; ?>"><?php echo $name; ?></a></td>
    <td class="tournytextlite"><?php echo $age; ?>&nbsp;&nbsp;<?php echo $age2; ?></td>
    <td class="tournytextlite">$<?php echo $cost; ?></td>
    <td class="tournytextlite"><?php echo $games; ?></td>
    <td class="tournytextlite"><a href="tournament_reg<?php echo $age; ?>.php">Register</a></td>
    </tr><?php } ?>

    Just as a note, this is a cheap trick, I am not sure if there is an easier/more efficient way to do this.

  5. #5
    Join Date
    Nov 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Worked great, thanks I really appreciate it.

  6. #6
    Join Date
    Feb 2005
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Your welcome, it was no problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •