SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would I go about alternating row colors in a table with PHP? Thanks...

    ------------------
    WebDevHQ.com - The Web Developer Headquarters! HUNDREDS of articles, reviews tools and more!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just bookmarked this yesterday. Haven't used it yet, but I'm guessing it works:
    http://www.faqts.com/knowledge-base/.../aid/783/fid/9

    ------------------
    "Whatever can be said can be said clearly." -- Ludwig Wittgenstein

  3. #3
    exit();
    Join Date
    Jul 2000
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems that one works great for a controlled loop but how you will you know how many records you will have each time, I use this to get the same effect:

    $dbrow1 = "#ffffff";
    $dbrow2 = "#eeeeee";
    $rowcolor = $dbrow1;

    while ($myrow = mysql_fetch_array($result)) {
    print '<tr bgcolor='. $rowcolor .'>';

    print '<td>some data</td>';

    print '</tr>'; }

    //Change row colors
    if ($rowcolor == $dbrow1) {
    $rowcolor = $dbrow2;
    } else {
    $rowcolor = $dbrow1;
    }


    }


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
  •