Hello, I am trying to paginate the results of the query and also have alternate row colours. For some reason when i search there is no error but my problem is that neither the pagination or alternate colour rows come up. Here is the code:
...<?php
print "<table border='0' bgcolor='#CCCCCC' align='center'><tr><td>
<form action='echo $PHP_SELF' method=get>
<p>By Hub:
<select name='search_hub' id='search_hub'><option>SELECT</option>
<option value='ypad'>Adeliade</option><option value='ybbn'>Brisbane</option><option value='ypdn'>Darwin</option>
<option value='ymml'>Melbourne</option><option value='ypph'>Perth</option><option value='yssy'>Sydney</option>
<option>---------------------</option><option value='nzaa'>Auckland</option><option value='nzch'>Christchurch</option><option>---------------------</option>
<option value='egll'>London</option><option value='klax'>Los Angeles</option><option value='wsss'>Singapore</option><option value='rjaa'>Tokoyo</option></select>
<font color='#CCCCCC'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
<input name='searchr' type='submit' value='Search'>
</form></td></tr></table>";
$sql = "SELECT COUNT(routes.routeid, depart.depart, depart.departcode, arrive.arrive, arrive.arrivecode) AS Total
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);
$row = mysql_fetch_array($result);
$total = $row['Total'];
$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']."'
ORDER BY routeid";
if (empty($GET['search_hub'])) {
$search_hub = 0;
$sql .= "LIMIT $search_hub, $limit"; }
else {
$search_hub = $GET['search_hub'];
$sql .= "LIMIT $search_hub, $limit"; }
if ($GET['search_hub']) {
$result = mysql_query($sql, $db);
$sql_rows = mysql_num_rows($result);
print "<table width='75%' border=0 align='center'>";
print "<tr bgcolor='$rowcolour'><th><p>Route Code</th><th><p>Departure Airport</th><th><p>Code</th><th><p>Arrival Airport</th><th><p>Code</th></tr>";
for ($a = 0; $a < $sql_rows; $a++) {
$row = mysql_fetch_array($result);
$rowclour = ($rowcount % 2) ? $colour1 : $colour2;
print "<tr><td><p>AR".$row['routeid']."</td>";
print "<td><p>".$row['depart']."</td>";
print "<td><p>".$row['departcode']."</td>";
print "<td><p>".$row['arrive']."</td>";
print "<td><p>".$row['arrivecode']."</td></tr>";
$rowcount++; }
print "</table>"; }
else (print "Sorry, your serach for '".$GET['search_hub']."' did not return any result"); // no match is found
if ($total > 0) {
if ($search_hub < $total && $search_hub > 0) {
$res1 = $search_hub - $limit;
echo "<a href=\"routesearch.php?search_hub=$res1&search_hub=".$GET['search_hub']."\"><p>Previous Page</a>"; }
$pages = $total / $limit;
if ($pages > 0) {
for ($b = 0, $c = 1; $b < $pages; $b++, $c++) {
$res1 = $limit * $b;
echo "<a href=\"routesearch.php?search_hub=$res1&search_hub=".$GET['search_hub']."\"><p>$c</a>\n"; }
}
if ($search_hub >= 0 && $search_hub < $total) {
$res1 = $search_hub + $limit;
if ($res1 < $total) {
echo "<a href=\"routesearch.pjp?search_hub=$res1&search_hub=".$_GET['search_hub']."\"><p>Next Page</a>"; }
}
}
mysql_close($db);
?> ...
There must be something wrong with the code. Can anyone help me? Thanx
N.B The values of some varibles (eg. $limit, $colour1, $colour2, $db, etc.) are set on db.php and I have a include() at the top of the doc to include them in the page.
😕