Prev Next Again yes I have searched!
Posted: Thu Sep 12, 2002 3:07 am
Ok first one more time I love this place [end arse kissing] 
Now I have the next and previous links working, however I need to figure out how to stop it from increasing the page id when there are no more results to display. In other words if the next page is going to be blank why bother adding the Next link right. Sure easy you say? .... well here is the trick. I am reading a GDBM file in to a hash using php and I cant figure out how to tell it what the last key is. Right now it works "Gheto style" meaning is been split in to rows of 10 and and will only stop when the current page is blank. so if second to last page only has 1 value returned, I still get my next link and an empty page once clicked. Here is the code:
PS some variables are set on an include so if you dont see it set here thats why like $counter is my gdbm file.
Now I have the next and previous links working, however I need to figure out how to stop it from increasing the page id when there are no more results to display. In other words if the next page is going to be blank why bother adding the Next link right. Sure easy you say? .... well here is the trick. I am reading a GDBM file in to a hash using php and I cant figure out how to tell it what the last key is. Right now it works "Gheto style" meaning is been split in to rows of 10 and and will only stop when the current page is blank. so if second to last page only has 1 value returned, I still get my next link and an empty page once clicked. Here is the code:
PS some variables are set on an include so if you dont see it set here thats why like $counter is my gdbm file.
Code: Select all
<?
print "<center>";
print "<table border=1><tr><td>Counter URL</td></tr>";
$dd=dba_open("$counter",'r','gdbm') || print "No dbm\n";
$k = dba_firstkey($dd);
while ($k != false)
{
$i++;
$mallї] = $k;
$k = dba_nextkey($dd);
};
$pid = $_GETї'pid']; // GRAB THE PAGE ID FROM GET
if(empty($pid) || $pid < 1){
$pid = 1;
} // CHECK THAT ITS REALLY A PAGE
$display = 9; // NUMBER PER PAGE - 1 remember we start @ 0!!
$end = $pid * $display;
$beg = $end - $display;
$next = $pid + 1;
$prev = $pid - 1;
for ($i=0;$i<count($mall); $i++)
{
if ( ($i >= $beg) && ($i <= $end) )
{
$val = $mallї$i];
$key = dba_fetch($val,$dd);
$splitkey = unpack("i2int",$key);
$count = $splitkeyїint1];
$changetime = $splitkeyїint2];
print "<tr><td><input type=checkbox name=theurlї'.$i.'] value=$val>$val</td></tr>";
};
};
print "</table></center>";
if ($pid <= 1)
{
print "<table border=0><tr><td align="left" colspan="3">ї Previous Page ] <a href="$PHP_SELF?pid=$next">ї Next Page]</a></td></tr></table><br>";
}
elseif ($count == false)
{
print "<table border=0><tr><td align="left" colspan="3"><a href="$PHP_SELF?pid=$prev">ї Previous Page ]</a> ї Next Page]</td></tr></table><br>";
}
else
{
print "<table border=0><tr><td align="left" colspan="3"><a href="$PHP_SELF?pid=$prev">ї Previous Page ]</a> <a href="$PHP_SELF?pid=$next">ї Next Page]</a></td></tr></table><br>";
}
?>