Page 1 of 1

Alternate coloured row code problem

Posted: Tue Jul 15, 2003 5:34 am
by mndwn
Hello, I am having problems getting the colours to show. Here is the code:

Code: Select all

<?php
$colour1 = '#CCCCCC';
			  $colour2 = '#FFFFFF';
			  $rowcount = 0;
					if ($_GET['search_hub']) {
					  $sql = "SELECT routes.routeid, depart.depart, depart.departcode, arrive.arrive, arrive.arrivecode
					        FROM (routes INNER JOIN depart
							ON routes.departid = depart.departid)
							INNER JOIN arrive ON routes.arriveid = arrive.arriveid
					        WHERE depart.departcode = '".$_GET['search_hub']."'";
                       $result = mysql_query($sql, $db);
					   print "<table width='75%' border=0 align='center'>";
                       print "<tr bgcolor'$rowcolour'><th><p><b>Route Code</b></th><th><p><b>Departure Airport</b></th><th><p><b>Code</b></th><th><p><b>Arrival Airport</b></th><th><p><b>Code</b></th></tr>";
					while
					   ($row = mysql_fetch_array($result)) {
                        print "<tr><td align='center'><p>AR".$row['routeid']."</td>";
						print "<td align='center'><p>".$row['depart']."</td>";
						print "<td align='center'><p>".$row['departcode']."</td>";
						print "<td align='center'><p>".$row['arrive']."</td>";
						print "<td align='center'><p>".$row['arrivecode']."</td></tr>";
						$rowcolour = ($rowcount%2)?$colour1:$colour2;
						$rowcount++; }
 print "</table>"; }
?>
Which part of the code may be causing the problem and how do i fix it so that the alternate colours show on the page. Thanx

Posted: Tue Jul 15, 2003 5:50 am
by Wayne

Code: Select all

print "<tr bgcolor='$rowcolour'><th><p><b>Route Code</b></th><th><p><b>Departure
you forgot the = after bgcolor, also for the above code $rowcolour isn't set so no colour will be used and in the mysql loop you didnt use the row colour at all.

Code: Select all

print "<tr bgcolor='$rowcolour'><td align='center'><p>AR".$row&#1111;'routeid']."</td>";

Thanx

Posted: Tue Jul 15, 2003 6:09 am
by mndwn
Thanx it works great.

Posted: Tue Jul 15, 2003 6:12 am
by mndwn
Every other row except the first has the colour, how do i fix that?

Posted: Tue Jul 15, 2003 7:22 am
by Wayne
put

Code: Select all

$rowcolour = $colour1;
or

Code: Select all

$rowcolour = $colour2;
at the top of the script, after you declare $colour1 & $colour2

Posted: Tue Jul 15, 2003 8:10 am
by mndwn
Thanx, everything works great and makes the results look much better, thanx again :)

Posted: Tue Jul 15, 2003 11:47 pm
by EvilWalrus
For the hell of it, i created this a while ago...

http://www.evilwalrus.com/viewcode.php?codeEx=666

Have at it...