I don't know if this is a better way to do it, but here's how I do it:

$return = mysql_query("SELECT This FROM That WHERE This = That");
        Print "<table>
For($i=1;$i<=count(mysql_num_rows($return);$i++)
        If($i % 2 == 0){$color="color1";} else {$color="color2";}

        Print " <tr bgcolor='#$color'>          ".
                "               <td>$value[$i]</td>     ".
                "       </tr>                                   "
        ;
}
        Print "</table>                                 "
        ;


Ryan


-----Original Message-----
From: Lee Willmann [mailto:[EMAIL PROTECTED]] 
Sent: Friday, November 30, 2001 10:51 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: Alternating rows pulled from database

I guess it would since you're doing basically the same thing, just a
different route.


"Mrbaseball34" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED]
> says...
> > Here's what I did to get alternating row colors on a results page... I'm
not
> > sure that I follow what you are asking, but I hope this will help you:
> >
> >
> >   $color_one = "dddddd";
> >   $color_two = "cccccc";
> >   $row_count = 0;
> > // SEND QUERY
> > while (row = fetch array(result))
> > {
> >  $row_color = ($row_count % 2) ? $color_one : $color_two;
> > other fields from DB
> > echo "<tr bgcolor=$row_color">;
> > echo "<td>";
> > echo data out
> > echo "</td>";
> > echo "</tr>";
> > $row_count++;
> > }
> >
> >
> > This is a really simple system. It uses the modulus (%) operator. If the
> > result of the math is even it uses color_one otherwise it uses
color_two..
> >
> > I found it somewhere, can't remember where right now.. But at least it
works
> > and it's only a few lines of code!!
> >
> <SNIP>
>
> Think this would work?
>
>        $rowcount = 0
>        while($forum = $db->fetch_array($query)) {
>          $forumlist .= ($row_count % 2) ?
>                        forum($forum, "index_forum") :
>                        forum($forum, "index_forum2");
>          $rowcount++;
>        }
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to