When I wrote my first article on this subject,
my intention was NOT to provide working code but rather to provide a thought
process that individuals could use to solve their own unique problems.
Judging by some of the comments and questions posted here, that was not
what most people wanted.
my intention was NOT to provide working code but rather to provide a thought
process that individuals could use to solve their own unique problems.
Judging by some of the comments and questions posted here, that was not
what most people wanted.
Unfortunately, I have not the time or desire to write code that will work
for all individuals in all cases. The following code will work fine
(with, possibly, some light changes to the HTML to suit your needs/tastes)
in most instances. Since this code ONLY provides incremental page links,
it is not suited to instances where there will be many resulting pages, but
should be OK for instances with between 0 to approximately 30 pages depending
on the width of the area in which you place the code.
for all individuals in all cases. The following code will work fine
(with, possibly, some light changes to the HTML to suit your needs/tastes)
in most instances. Since this code ONLY provides incremental page links,
it is not suited to instances where there will be many resulting pages, but
should be OK for instances with between 0 to approximately 30 pages depending
on the width of the area in which you place the code.
That said, let’s move on to the code itself:
<?php
function pagenav() {
global $limit,$offset,$numpage,$where;
if ($where) {
$safewhere=urlencode($where);
}
echo "
<TABLE CELLPADDING=0 BORDER=0 CELLSPACING=5 WIDTH=100>
<TR>
<TD ALIGN=RIGHT>";
if (
$offset>=$limit) {
$newoff=$offset-$limit;
echo "<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
<-- PREV</A>
</TD>";
} else {
echo "<-- PREV";
}
echo
"<TD ALIGN=CENTER> ";
for (
$i=1;$i<=$numpage;$i++) {
if ((($i-1)*$limit)==$offset) {
print "$i ";
} else {
$newoff=($i-1)*$limit;
echo
"<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
$i</A> ";
}
}
echo " </TD>
<TD ALIGN=LEFT>";
if ($offset!=$limit*($numpage-1)) {
$newoff=$offset+$limit;
echo "<A HREF="$PHP_SELF?offset=$newoff&where=$safewhere">
NEXT--></A>
</TD>";
}else{
echo "NEXT--></TD>";
}
echo "</TR>
</TABLE>";
}
// END FUNCTION
?>
The script relies upon three to four outside variables. The first two,
$limit and $offset can be set by adding the following lines at the beginning of your code:
$limit and $offset can be set by adding the following lines at the beginning of your code:
<?php
// set this to the number of results you wish on each page
$limit=20;
// if no offset has been passed, offset should be 0
if (!$offset) {
$offset=0;
}
?>