Re: Alternating table rows...
| From: | Robert Cummings | Date: | Fri, 10 May 2002 19:30:16 +0000 |
| Subject: | Re: Alternating table rows... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96995@lists.php.net to get a copy of this message | ||
The more generic approach:
function getNextColour( &$lastIndex, $colourList )
{
return $colourList[(++$lastIndex % count( $colourList ))];
}
$colours = array
(
'#ff0000',
'#00ff00',
'#0000ff'
);
$index = 0;
foreach( $rows as $aRow )
{
echo '<tr bgcolor="'.getNextColour( $index, $colours ).'">'
.$aRow
.'</tr>'."\n";
}
Cheers,
Rob.
-----------------------------------------------------------------------------
Jay Blanchard wrote:
>
> [snip]
> Is there a way for me to do one of the following:
>
> 1) Test to see if $i is an even or odd number?
> 2) Grab more than one line from the database at a time, and just put in two
> table rows at once?
> [/snip]
>
> <?
> $rowcount = 0;
> while($dbrowa = mysql_fetch_object($dbseta)){
> $dbrowb = mysql_fetch_object($dbsetb);
> //change the color of alternating rows
> $rowcount ++;
> if ($rowcount == 1){
> print("<tr bgcolor=\"#FFFF99\">\n");
> }
> elseif ($rowcount <> 1) {
> print("<tr>\n");
> $rowcount = 0;
> }
>
> This way you don't have to know even or odd.
> $rowcount is 0
> $rowcount is set to one and printed in a different color
> $rowcount is set to two, which is not equal to one, so does elseif and is
> set to zero
>
> HTH!
>
> Jay
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
.-----------------.
| Robert Cummings |
:-----------------`----------------------------.
| Webdeployer - Chief PHP and Java Programmer |
:----------------------------------------------:
| Mail : mailto:robert.cummings@webmotion.com |
| Phone : (613) 731-4046 x.109 |
:----------------------------------------------:
| Website : http://www.webmotion.com |
| Fax : (613) 260-9545 |
`----------------------------------------------'