Page 1 of 1

Prev Next Again yes I have searched!

Posted: Thu Sep 12, 2002 3:07 am
by MAsKrA
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.

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)
           &#123;
            $i++;
            $mall&#1111;] = $k;
            $k = dba_nextkey($dd);
           &#125;;
		$pid = $_GET&#1111;'pid']; // GRAB THE PAGE ID FROM GET 
		if(empty($pid) || $pid < 1)&#123; 
		$pid = 1; 
		&#125; // 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++)
         &#123;
		  if ( ($i >= $beg) && ($i <= $end) )
		  &#123;
          $val = $mall&#1111;$i];
          $key = dba_fetch($val,$dd);
          $splitkey = unpack("i2int",$key);
          $count = $splitkey&#1111;int1];
          $changetime = $splitkey&#1111;int2];
		  print "<tr><td><input type=checkbox name=theurl&#1111;'.$i.'] value=$val>$val</td></tr>";
		  &#125;;
		 &#125;;
		  print "</table></center>";		   
    if ($pid <= 1)
	&#123;
	print "<table border=0><tr><td align="left" colspan="3">&#1111; Previous Page ] <a href="$PHP_SELF?pid=$next">&#1111; Next Page]</a></td></tr></table><br>";
	&#125;
	elseif ($count == false)
	&#123;
	print "<table border=0><tr><td align="left" colspan="3"><a href="$PHP_SELF?pid=$prev">&#1111; Previous Page ]</a> &#1111; Next Page]</td></tr></table><br>";
	&#125;
	else
	&#123;
	print "<table border=0><tr><td align="left" colspan="3"><a href="$PHP_SELF?pid=$prev">&#1111; Previous Page ]</a> <a href="$PHP_SELF?pid=$next">&#1111; Next Page]</a></td></tr></table><br>";
	&#125;
?>

Posted: Thu Sep 12, 2002 3:12 am
by MAsKrA
Ahhhhh if you want to see it action click:

http://gamedestroyers.com/dev/counter/p ... n_test.php

Posted: Thu Sep 12, 2002 8:16 am
by MAsKrA
w00t damn right I figure it out on my own. Damn I am getting better at this :D :D

Thanks anyways!
:twisted:

Posted: Thu Sep 12, 2002 9:23 am
by phice
That's the only way we should learn the Prev & Next links. It's very easy, once you think about it. ;)