PDA

View Full Version : alternating colors in PHP?



Force
October 26th, 2002, 19:55
I GOT IT WORKING! NO NEED TO TRY AND HELP! THANKS!

does anyone know how i can make alternating row colors in this script? for example; row 1 is blue, row 2 is red, row 3 is blue, row 4 is red, etc.

i would like to get this working in php. i dont want any mysql, javascript, or css.

if anyone knows how to do this please let me know.

[EDIT]: I have already worked on this for many hours, so please dont say something like "search the forum", "try hotscript.com", or "search google".

Thanks in Advance

biggulp
October 27th, 2002, 09:13
$alternate = 2;
while (condition) {
if ($alternate == 1) {
$color = "#000000";
$alternate = 2;
} else {
$color = "#666666";
$alternate = 1;
}
print "<tr bgcolor=\"$color\"><td>data</td></tr>";
}

something like that.

Force
October 27th, 2002, 10:07
thanks for the help biggulp, but im still having some problems with it. it is repeating the first file infinite times in the rows. do you know where i should put the code you gave me in my script?

ansa
October 27th, 2002, 13:04
put it instead of you line that reads



echo "<tr><td bgcolor=\"#000000\"><td></tr>";



Andy.

Force
October 27th, 2002, 14:51
Originally posted by ansa
put it instead of you line that reads



echo "<tr><td bgcolor=\"$color\"><td></tr>";



Andy.

thanks, but it doesnt work. it needs to be like:

echo "<tr><td bgcolor=\"#000000\">$title<td></tr>";

and every line will have a different title and color

Force
October 27th, 2002, 15:52
ok, i think i almost have it. can someone PLEASE tell me what im doing wrong. everything works perfect, except every row is written twice.

thanks for helping me out with this

spec
October 27th, 2002, 16:29
<?
$colornow = 1;
for($x=0;$x<=$count;$x++) {
if($colornow == 1) $c = "#000000";
if($colornow == 2) $c = "#111111";

echo print "<tr><td bgcolor=\"$c\"><a href=\"http://www.domain.com/download.php?a=$name&b=$letter&c=$file\">$filename</a></td><td bgcolor=\"$c\" align=\"right\"><font face=\"verdana, arial, helvetica\" size=\"2\">$show_filesize</font></td></tr>";

if($colornow == 1) $colornow = 2;
if($colornow == 2) $colornow = 1;
}
?>

Force
October 27th, 2002, 19:49
ok, i got it working. thanks for the help everyone!!