Hi all,
I've been working on a set of Next/Previous links, and in general after some help its working nicely!
Except for one problem..
I cant seem to get the next link to work right.
First off if there are less than 20 records, the next link is still displayed.. it shouldnt be.
Also if the are more than 60 records, the next link disappears.. not allowing the user to view past the 60th record.
Last but not least, the link should not be visible on the final page, there is no Next past the final record!
Here's what Ive done, hope someone can help me out here.. been plugging at this for nearly 3 days now 🙁
Regards
Lee
else {
// WHAT MAPS HAVE WE GOT?
// ***** show map list
if (!empty($offset)) {$offsetstring = $offset . ",";}
else {$offsetstring = "";}
if ($offset > 20) {$prevoffset=$offset - 20;}
else {$prevoffset=0;}
$result = mysql_query("SELECT * FROM ccentral_maps ORDER BY MAP LIMIT " . $offsetstring . " 20");
if ($myrow = mysql_fetch_array($result)) {
$numrows = mysql_num_rows($result);
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">\n";
echo "<tr>\n<td colspan=\"3\"><center><strong>Maps - Admin</strong></center></td>\n";
do {
echo "<tr>\n<td width=\"50%\">";
printf("<a href=javascript:openWindow(\"../maps/maps.php?id=%s&detail=1\")>%s</a><br>\n</td>\n", $myrow["id"], $myrow["MAP"]);
echo "<td width=\"25%\">";
printf("<center><a href=\"%s?id=%s&edit=1\">EDIT</a></center></td>\n", $PHP_SELF, $myrow["id"]);
echo "<td width=\"25%\">";
printf("<center><a href=\"%s?id=%s&verify=1\">DELETE</a></center></td>\n</tr>\n", $PHP_SELF, $myrow["id"]);
}
while ($myrow = mysql_fetch_array($result));
$numrows = mysql_num_rows($result);
echo "</table>\n\n";
$nextoffset=($offset + 20);
$prevoffset=($offset - 20);
if ($nextoffset > 20) {
if ($prevoffset < 20) {
echo "<br><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#000000\">\n<tr bordercolor=\"#CCCCCC\">\n<td width=\"33%\">";
printf ("<div align=\"left\"><A HREF=\"$PHP_SELF\">« « Previous</a></div></td>\n");
} else {
echo "<br><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#000000\">\n<tr bordercolor=\"#CCCCCC\">\n<td width=\"33%\">";
printf ("<div align=\"left\"><A HREF=\"$PHP_SELF?&offset=$prevoffset\">« « Previous</a></div></td>\n");
echo "<td width=\"34%\"><div align=\"center\">";
printf ("<a href=\"%s?addmap=1\">Add A New Map!</a></div></td>\n\n", $PHP_SELF); }
}
else
{
echo "<br><table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#000000\">\n<tr bordercolor=\"#CCCCCC\">\n<td width=\"33%\"><div align=\"left\"> </div></td>";
echo "<td width=\"34%\"><div align=\"center\">";
printf ("<a href=\"%s?addmap=1\">Add A New Map!</a></div></td>\n\n", $PHP_SELF);
}
if ($offset <= $numrows) {
echo "<td width=\"33%\">";
printf ("<div align=\"right\"><A HREF=\"$PHP_SELF?&offset=$nextoffset\">Next » »</a></div></td></tr></table>");
}
else {
echo "<td width=\"33%\">";
printf ("<div align=\"right\"> </div></td></tr></table>");
}
}
else
{
// ***** no records to display
echo "<center><table width=\"50%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">\n";
echo "<tr><td><center><strong>Sorry, no map records were found!</strong></td></tr></table></center>";
echo "<br><br><center><table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">\n";
printf("<tr><td><center><strong><a href=\"%s?addmap=1\">Add A New Map!</a></strong></td></tr></table></center>\n", $PHP_SELF);
}
}
?>