Alternate coloured row code problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mndwn
Forum Newbie
Posts: 6
Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia

Alternate coloured row code problem

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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>";
mndwn
Forum Newbie
Posts: 6
Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia

Thanx

Post by mndwn »

Thanx it works great.
mndwn
Forum Newbie
Posts: 6
Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia

Post by mndwn »

Every other row except the first has the colour, how do i fix that?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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
mndwn
Forum Newbie
Posts: 6
Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia

Post by mndwn »

Thanx, everything works great and makes the results look much better, thanx again :)
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

For the hell of it, i created this a while ago...

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

Have at it...
Post Reply