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
mndwn
Forum Newbie
Posts: 6 Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia
Post
by mndwn » Tue Jul 15, 2003 5:34 am
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
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Tue Jul 15, 2003 5:50 am
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ї'routeid']."</td>";
mndwn
Forum Newbie
Posts: 6 Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia
Post
by mndwn » Tue Jul 15, 2003 6:09 am
Thanx it works great.
mndwn
Forum Newbie
Posts: 6 Joined: Tue Jul 15, 2003 5:34 am
Location: Sydney, NSW, Australia
Post
by mndwn » Tue Jul 15, 2003 6:12 am
Every other row except the first has the colour, how do i fix that?
Wayne
Forum Contributor
Posts: 339 Joined: Wed Jun 05, 2002 10:59 am
Post
by Wayne » Tue Jul 15, 2003 7:22 am
put
or
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 » Tue Jul 15, 2003 8:10 am
Thanx, everything works great and makes the results look much better, thanx again