Jump to content


Photo

pagination


  • Please log in to reply
5 replies to this topic

#1 piet bierbuik

piet bierbuik
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 16 October 2006 - 06:36 PM

hi,

i've created a pagination script and it works... half, not like i want.
http://84.244.181.93.../pagenation.php
1. the PREV button doesn't work.
2. if i press like same number 10, the numbering say its on page 11.

can someone help me alternate this file.

oops, sorry

<?php
include ("connect.php");

$limit = 5;     
$query_count = "SELECT * FROM uitgaan";     
    // count(*) is better for large databases (thanks Greg!) 
$result_count   = mysql_query($query_count);        
$totalrows  = mysql_num_rows($result_count);     
$page = $_GET['page'];

if(empty($page))
	{   
        $page = 1;    
    } 
$limitvalue = $page * $limit - ($limit);
echo "<br>";
echo "-----------------------------------------";
echo "<br>";
echo '$page=', $page;
echo "<br>";
echo '$limitvalue=',$limitvalue;
echo "<br>";
echo "-----------------------------------------";
echo "<br>";
echo "<br>";
   
$query  = "SELECT * FROM uitgaan LIMIT $limitvalue, $limit";         
$result = mysql_query($query) or die("Error: " . mysql_error());  

if(mysql_num_rows($result) == 0)
	{ 
        echo("Nothing to Display!"); 
    } 
	
while ($rij = mysql_fetch_array ($result))
	{
		echo $rij['naam'],"</BR>";
	}
	
if($page != 1)
{  
	$pageprev = $page++; 
	echo("<a href=\"$_SERVER[PHP_SELF]?page=$pageprev\">PREV".$limit."</a> ");    
}
else
{ 
	echo("PREV".$limit." ");  
}

$numofpages = $totalrows / $limit;   

for($i = 1; $i <= $numofpages; $i++)
{
	if($i == $page)
		{ 
			echo($i." ");
		}
	else
		{ 
            echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
        } 
         
}


if(($totalrows % $limit) != 0)
{      
	if($i == $page)
		{ 
			echo($i." "); 
		}
	else
		{ 
			echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> "); 
		} 
} 

if(($totalrows - ($limit * $page)) > 0)
{ 
$pagenext   = $page--; 
	echo("<a href=\"$_SERVER[PHP_SELF]?page=$pagenext\">NEXT".$limit."</a>"); 
}

	else
		{
			echo("NEXT".$limit);
		} 

?> 


#2 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 16 October 2006 - 06:39 PM

Can you provide code please?  It will be hard to determine the error without the code. ;)
<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 16 October 2006 - 06:39 PM

Post your code so we can see what's going on

EDIT: beat me to it :)
Ray

#4 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 16 October 2006 - 09:39 PM


change $pageprev = $page++; to $pageprev = $page-1;

and $pagenext  = $page--; to $pagenext  = $page+1;

#5 piet bierbuik

piet bierbuik
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 17 October 2006 - 09:04 AM

yes it worked thx you sasa.
i thought $i++ is the same as $i+1, but now it works so im happy.

here is the full code:

<?php
include ("connect.php");

$limit = 5;     
$query_count = "SELECT * FROM table";
$result_count   = mysql_query($query_count);        
$totalrows  = mysql_num_rows($result_count);     
$page = $_GET['page'];

if(empty($page))
	{   
        $page = 1;    
    } 
$limitvalue = $page * $limit - ($limit);   
$query  = "SELECT * FROM table LIMIT $limitvalue, $limit";         
$result = mysql_query($query) or die("Error: " . mysql_error());  

if(mysql_num_rows($result) == 0)
	{ 
        echo("Nothing to Display!"); 
    } 
	
while ($rij = mysql_fetch_array ($result))
	{
		echo $rij['naam'],"</BR>";
	}
	
if($page != 1)
{  
	$pageprev = $page-1; 
	echo("<a href=\"$_SERVER[PHP_SELF]?page=$pageprev\">PREV".$limit."</a> ");    
}
else
{ 
	echo("PREV".$limit." ");  
}

$numofpages = $totalrows / $limit;   

for($i = 1; $i <= $numofpages; $i++)
{
	if($i == $page)
		{ 
			echo($i." ");
		}
	else
		{ 
            echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
        } 
         
}


if(($totalrows % $limit) != 0)
{      
	if($i == $page)
		{ 
			echo($i." "); 
		}
	else
		{ 
			echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> "); 
		} 
} 

if(($totalrows - ($limit * $page)) > 0)
{ 
$pagenext = $page+1; 
	echo("<a href=\"$_SERVER[PHP_SELF]?page=$pagenext\">NEXT".$limit."</a>"); 
}

	else
		{
			echo("NEXT".$limit);
		} 

?> 



#6 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 17 October 2006 - 09:15 AM

yes it worked thx you sasa.
i thought $i++ is the same as $i+1, but now it works so im happy.


Actually what you want (I know this is correct in C++) is ++$i
<?php

$i = 0;
$tmp = $i++;
echo $tmp ."<br />";

$tmp = ++$i;
echo $tmp ."<br />";

?>

This will produce:
0
2

SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users