Hello,... please look at this <?PHP $sourceData = mysql_query(" select * from member where loc='a'",$connection); echo " <TABLE width=\"500\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <TR> <TD width=\"10\" class=\"header\">No</TD> <TD width=\"140\" class=\"header\">Name</TD> <TD width=\"350\" class=\"header\">Address</TD> </TR> "; while($theMember = mysql_fetch_array($sourceData)) { echo" <TR> <TD class=\"content\">" . $theMember["id"] . "</TD> <TD class=\"content\">" . $theMember["memName"] . "</TD> <TD class=\"content\">" . $theMember["memAddress"] . "</TD> </TR> "; } echo " </TABLE> "; ?> PHP: my question is, how can i give a bgcolor="#f5f5f5" on odd row and give a bgcolor="#c3c3c3" on even row,...so the result rows will has different color for eact it encrease. can i do it with "while" or i should do it with "do" could anyone here help me with an example script, please. i really appriciate it.. Best regards
How about something like this: <?PHP $sourceData = mysql_query(" select * from member where loc='a'",$connection); $color="#f5f5f5"; echo " <TABLE width=\"500\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <TR> <TD width=\"10\" class=\"header\">No</TD> <TD width=\"140\" class=\"header\">Name</TD> <TD width=\"350\" class=\"header\">Address</TD> </TR> "; while($theMember = mysql_fetch_array($sourceData)) { echo" <TR bgcolor=" . $color . "> <TD class=\"content\">" . $theMember["id"] . "</TD> <TD class=\"content\">" . $theMember["memName"] . "</TD> <TD class=\"content\">" . $theMember["memAddress"] . "</TD> </TR> "; if($color=="#f5f5f5"){ $color="#c3c3c3"; } else { $color="#f5f5f5"; } } echo " </TABLE> "; ?> PHP:
Watch out if you are using that Javscript which allow you to sort the table by clicking the table headers It totally fucks up the alternating backgrounds as each row is moved around.