piet bierbuik Posted October 16, 2006 Share Posted October 16, 2006 hi,i've created a pagination script and it works... half, not like i want.http://84.244.181.93/~vandenberg/onlinetilburg/pagenation.php1. 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[code]<?phpinclude ("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); } ?> [/code] Link to comment https://forums.phpfreaks.com/topic/24125-pagination/ Share on other sites More sharing options...
makeshift_theory Posted October 16, 2006 Share Posted October 16, 2006 Can you provide code please? It will be hard to determine the error without the code. ;) Link to comment https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109668 Share on other sites More sharing options...
craygo Posted October 16, 2006 Share Posted October 16, 2006 Post your code so we can see what's going onEDIT: beat me to it :)Ray Link to comment https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109669 Share on other sites More sharing options...
sasa Posted October 16, 2006 Share Posted October 16, 2006 change $pageprev = $page++; to $pageprev = $page-1; and $pagenext = $page--; to $pagenext = $page+1; Link to comment https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109749 Share on other sites More sharing options...
piet bierbuik Posted October 17, 2006 Author Share Posted October 17, 2006 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:[code]<?phpinclude ("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); } ?> [/code] Link to comment https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109906 Share on other sites More sharing options...
xsist10 Posted October 17, 2006 Share Posted October 17, 2006 [quote author=piet bierbuik link=topic=111683.msg452994#msg452994 date=1161075883]yes it worked thx you sasa.i thought $i++ is the same as $i+1, but now it works so im happy.[/quote]Actually what you want (I know this is correct in C++) is ++$i[code]<?php$i = 0;$tmp = $i++;echo $tmp ."<br />";$tmp = ++$i;echo $tmp ."<br />";?>[/code]This will produce:[code]02[/code] Link to comment https://forums.phpfreaks.com/topic/24125-pagination/#findComment-109909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.