Hi all,
I'm in the process of creating a Next/Previous script....but to no avail.
At the moment i'm getting the Next link showing up even when there are less that 20 results on the page.
Also when i do goto a page that has more than 20 results it displays the links correctly but if there are no more results after that i dont want the Next link to show.
Any ideas would be most appreciated.
You can see my example of what i'm trying to achieve at: http://www.1stopmotoring.net/auto.php?id=118
(if you click on the "Car Rental" link you will see what i mean)
Cheers,
micmac
<?
if(!isset($start)) $start = 0;
$row = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM cat1 WHERE CatParent = $id"));
if($row[0] > 0){
$result = mysql_query("SELECT * FROM cat1 WHERE CatParent = $id AND active='yes' ORDER BY pref, CatName LIMIT " . $start . ", 20");
$resultsnumber = mysql_numrows($result);
while($row = mysql_fetch_array($result)){
if( $row['country'] == "UK") {
$flag_pic = "uk_flag.gif";
} else if( $row['country'] == "US") {
$flag_pic = "usa_flag.gif";
} else if( $row['country'] == "AUS") {
$flag_pic = "aus_flag.gif";
} else if( $row['country'] == "Global") {
$flag_pic = "sw.gif";
}
if ( $row['confirm_cat'] != "nil") {
echo "<TABLE><TR>";
echo "<TD align=left vAlign=center width=\"29\"><a class=\"os\" href=\"auto.php?id={$row['CatID']}\"><IMG align=center alt=\"1 STOPMOTORING.NET\" border=0 src=\"images/$flag_pic\"></A>";
echo "</TD>";
echo "<TD align=left vAlign=center width=\"306\"><a class=\"os\" href=\"auto.php?id={$row['CatID']}\">{$row['CatName']} - $resultsnumber1</a></TD>";
echo "<TD align=left vAlign=center width=\"100\">< Click to view</TD>";
echo "</TR>";
} else {
if ( $row['confirm_cat'] != "nil") {
echo "<TABLE cellPadding=2 cellSpacing=0 width=480>";
echo "<TBODY><TR>";
echo "<TD align=left vAlign=center width=\"29\"><IMG align=center alt=\"1 STOPMOTORING.NET\" border=0 src=\"images/$flag_pic\">";
echo "</TD>";
echo "<TD align=left vAlign=center width=\"301\"><b>{$row['CatName']}</b>";
if ( $row['suburb'] != "") {
echo " - {$row['suburb']} - $resultsnumber1</TD>";
} else {
echo "</TD>";
}
if ($row['pref'] == 'S' || $row['pref'] == 'G'){
echo "<TD align=right vAlign=center width=\"105\"><a class=\"os\" href=\"{$row['url']}\" target=\"_blank\"><font size=\"1\">Website</font></a> | <a class=\"os\" href=\"auto.php?id={$row['CatID']}\"><font size=\"1\">Profile</font></a></TD>";
} else {
echo "<TD align=right vAlign=center width=\"105\"><a class=\"os\" href=\"{$row['url']}\" target=\"_blank\"><font size=\"1\">Website</font></a></TD>";
}
echo "</TR>";
echo "<TR>";
if ($row['info'] == ''){
echo "<TD align=left bgColor=#ffffff vAlign=center width=\"29\"></TD>";
echo "<TD align=left bgColor=#ffffff vAlign=center width=\"406\" colspan=\"2\"></TD>";
} else {
$str=$row['info'];
$max=170;
$modstr=((strlen($str)>$max)?substr($str,0,$max) . "..." : $str);
echo "<TD align=left bgColor=#f2f2f2 vAlign=center width=\"29\"></TD>";
echo "<TD align=left bgColor=#f2f2f2 vAlign=center width=\"406\" colspan=\"2\">$modstr</TD>";
}
echo "</TR>";
} else {
echo "<TABLE cellPadding=2 cellSpacing=0 width=480>";
echo "<TBODY><TR>";
echo "<TD align=left vAlign=center width=\"29\"><IMG align=center alt=\"1 STOPMOTORING.NET\" border=0 src=\"images/$flag_pic\">";
echo "</TD>";
echo "<TD align=left vAlign=center width=\"301\"><b>{$row['CatName']}</b>";
if ( $row['suburb'] != "") {
echo " - {$row['suburb']}</TD>";
} else {
echo "</TD>";
}
if ($row['pref'] == 'S' || $row['pref'] == 'G'){
echo "<TD align=right vAlign=center width=\"105\"><a class=\"os\" href=\"{$row['url']}\" target=\"_blank\"><font size=\"1\">Website</font></a> | <a class=\"os\" href=\"auto.php?id={$row['CatID']}\"><font size=\"1\">Profile</font></a></TD>";
} else {
echo "<TD align=right vAlign=center width=\"105\"><a class=\"os\" href=\"{$row['url']}\" target=\"_blank\"><font size=\"1\">Website</font></a></TD>";
}
echo "</TR>";
echo "<TR>";
if ($row['info'] == ''){
echo "<TD align=left bgColor=#ffffff vAlign=center width=\"29\"></TD>";
echo "<TD align=left bgColor=#ffffff vAlign=center width=\"406\" colspan=\"2\"></TD>";
} else {
$str=$row['info'];
$max=170;
$modstr=((strlen($str)>$max)?substr($str,0,$max) . "..." : $str);
echo "<TD align=left bgColor=#f2f2f2 vAlign=center width=\"29\"></TD>";
echo "<TD align=left bgColor=#f2f2f2 vAlign=center width=\"406\" colspan=\"2\">$modstr</TD>";
}
echo "</TR>";
}
}
}
echo "<TR><TD colspan=\"3\">";
$query = "SELECT count(*) as count FROM $table";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$numrows = $row['count'];
if($start >= 20)
echo "<a href=\"" . $PHP_SELF . "?id=$id&start=" . ($start - 20) . "\">Previous</a>";
if($numrows < ($start + 19))
echo "";
if($numrows > ($start + 20))
echo " <a href=\"" . $PHP_SELF . "?id=$id&start=" . ($start + 20) . "\">Next</a>";
echo "</TD></TR>";
}