#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Okay, I've been working with a specific routine for a while, and now have a need to come up with a slightly different method.

    The display I'm looking for would look something like this:

    DB Item 1 DB Item 2
    DB Item 3 DB Item 4

    etc..

    While that is being listed I want to also alternate the row background color(s).

    Now, I'm really not sure how to approach this one, I mean I know how to list them and alternate table rows when the output looks like this:

    DB Item 1
    DB Item 2
    DB Item 3
    DB Item 4

    So, does any one have any words of wisdow...

    Here's a quick snipit of code that I typically use for the above:

    $i = 0;
    while($myrow = mysql_fetch_array($result)) {

    $bgcolor = $bgColor1;
    $i % 2 ? 0: $bgcolor = $bgColor2;

    echo "<tr bgcolor="$bgcolor">
    <td>first thing</td>n
    <td>second thing</td>n
    </tr>";
    $i++;
    }

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    $numrows=mysql_num_rows($result);
    $odd="#cccccc";
    $even="#0000ff";
    $bgcol=$even;
    for ($i=1;$i<$numrows;$i++)
    {
    if ($bgcol==$even)
    { $bgcol=$odd }else{ $bgcol=$even }
    $data=mysql_fetch_row($result);
    if ($i!=$numrows)
    {
    $data2=mysql_fetch_row($result);
    }else{
    $data2[0]="&nbsp;";
    }
    print "<tr bgcolor=$bgcol>n";
    print "<td>$data[0]</td><td>$data2[0]</td>n";
    print "</tr>n";
    }

    HTH
  4. #3
  5. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks for the input.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    OOOPS. Got in a hurry there and messed that up. The for statement should be:

    for ($i=1;$i<$numrows;$i+=2)
  8. #5
  9. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
    OOOPS. Got in a hurry there and messed that up. The for statement should be:

    for ($i=1;$i<$numrows;$i+=2)
    [/quote]

    Thanks again.




    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

Similar Threads

  1. Replies: 5
    Last Post: July 29th, 2011, 10:21 PM
  2. Replies: 5
    Last Post: February 13th, 2004, 03:58 PM
  3. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  4. limit mysql display results into 3 table rows
    By bcounsell in forum MySQL Help
    Replies: 1
    Last Post: January 9th, 2004, 08:16 AM
  5. updating a field in a table with the rows rank
    By thatcoryguy in forum MySQL Help
    Replies: 0
    Last Post: January 3rd, 2004, 01:11 AM

IMN logo majestic logo threadwatch logo seochat tools logo