Wow you guys are going about that way more complicated than it needs to
be:

$i = 0;
echo "<TR BGCOLOR='#". (($i++ % 2 == 0) ? "'E3E3E3" : "FFFFFF") ."'>";

Then it just alternates and takes care of itself (plus you get a nice
little index counter as well  as a bonus if you want to use $i 

DÆVID.

"A good friend will come and bail you out of jail...but a true friend
will be sitting next to you in the holding cell, laughing and saying
-'That was fucking awesome!'" 

> -----Original Message-----
> From: Bobby Rahman [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, April 05, 2003 2:09 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [PHP] RE: newbie alternate row colours in dynamic table
> 
> 
> 
> 
> Hiya people
> 
> After a lot of soul searching, exploring the web and help 
> from many people I 
> came up with this simple solution:
> 
> Thank you Chris for explaining the toggle $colorset. In the 
> end I decided 
> this made life alot simplier.
> 
> (clearly the brackets have to be correctly aligned)
> 
> while( $row = mysql_fetch_array($db_result) )
> {
> echo("
>      <tr $c>
>      <td>" . $row['bugid'] . "</td>
>      </tr>
>      ");
> if ( !isset($c) )
> {
> $c = "bgcolor=#9999FF";
> echo $c;
> }
> else
> {
> unset($c);
> }
> }
> 
> 
> 
> 
> >From: Chris Hayes <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: [PHP] RE: newbie alternate row colours in dynamic table
> >Date: Sat, 05 Apr 2003 22:32:17 +0200
> >
> >At 22:14 5-4-2003, you wrote:
> >
> >
> >>Hiya I have a dynamic table and am trying to get the rows to be two 
> >>different alternate colours. well Ive looked at a couple of 
> snippets of 
> >>this colour code and previous mails regarding this. Im having major 
> >>troubles intergrating any of these suggestions with my 
> code. Can anyone 
> >>suggest where I am going wrong. Main problems are
> >>1. where to put the loop for changing the colour 
> (complicated due to the 
> >>loop retrieving data from db)i.e in the do loop....in the 
> while loop?
> >Within the loop that prints the rows, whcih is usually a 
> while loop. But 
> >that depends on your preferences.
> >
> >
> >>2. Also how to echo my rows in the colours.(something like 
> this I think)
> >>print "<tr bgcolor='$trcolor'>"$db_fetch['bugid']; ?></td>;
> >>
> >>
> >>e.g here is the code snippet for alternate coloured rows
> >>$trcolor="#F0F8FF";
> >>while ($myrow = mysql_fetch_array($result)){
> >>$colorset=0;
> >>if ($trcolor=='#F0F8FF'){
> >>$trcolor='#B0C4DE';
> >>$colorset=1;
> >>}
> >>if ($colorset==0){
> >>if ($trcolor=='#B0C4DE'){
> >>$trcolor='#F0F8FF';}
> >>}
> >>print "<tr bgcolor='$trcolor'>";
> >>}
> >I see that you are using a helping variable $colorset.
> >I have a problem reading your code in email, as i do not see 
> hte indents 
> >well, so i restructure it here with _ underscores to make 
> the indents 
> >survive the email program.
> >
> >
> >$trcolor="#F0F8FF";             //1
> >
> >while ($myrow = mysql_fetch_array($result))
> >{
> >___$colorset=0;
> >___if ($trcolor=='#F0F8FF')    //1
> >___{$trcolor='#B0C4DE'; //2
> >____$colorset=1;
> >___}
> >
> >___if ($colorset==0)
> >___{ if ($trcolor=='#B0C4DE')   //2
> >______{$trcolor='#F0F8FF';       //1
> >______}
> >___}
> >
> >print "<tr bgcolor='$trcolor'>";
> >}
> >
> >Lets walk through.
> >In the 1st walk,
> >1a) you enter with color#1 and colorset=0.
> >2b) the first 'if' then sets it to color#2 and colorset=1
> >3c) The second if sees that both conditions are true and set 
> the color back 
> >to color#1.
> >
> >So the first row prints color1.
> >
> >Ok. The code remembers the values, which are color#1 and colorset1.
> >In the next walkthrough,
> >2a) the colorset is set to 0 to start with.
> >At this moment you have the exact situation as with 1a).
> >
> >do you see that? it would be much easier to see what is 
> happening if you 
> >would have only colorset toggling its value and just before 
> printing, 
> >decide what the color is as a result of the value of colorset.
> >Give it a try!
> >
> >Basically:
> >
> >$colorset=0;
> >
> >while (....)
> >{ toggle collorset (toggle: if 1 then 0 and opposite)
> >  if colorser=0 color=ffffff else color=aaaaa
> >  print color.
> >}
> >
> >Chris Hayes
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> 
> _________________________________________________________________
> Surf together with new Shared Browsing 
> http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID
> =74&DI=1059
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to