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



Reply via email to