almystersv Posted January 29, 2008 Share Posted January 29, 2008 Hi Guys, I managed to get hold of this code and it does display the first 10 records but before it has dozens of lines with just th letter 'n'. also the PREV, NEXT and page number links do not work. <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location: login.php"); exit(); } require "connect.php"; $limit = 10; $query_count = "SELECT count(*) FROM product"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM product LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#E0E0E0"; // light gray ?> <table width ="100%" border="1"> <?php while($row = mysql_fetch_array($result)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } echo("<tr bgcolor=".$bgcolor.">n<td>"); echo($row["URN"]); echo("</td>n<td>"); echo($row["productName"]); echo("</td>n</tr>"); } echo("</table>"); if($page != 1){ $pageprev = $page--; ?> <a href=\"StationaryOrdersTEST.php&page=$pageprev\">PREV".$limit."</a> <?php }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ ?><a href=\"StationaryOrdersTEST.php?page=$i\">$i</a> <?php } } if(($totalrows % $limit) != 0){ if($i == $page) { echo($i." "); } else{ ?> <a href="StationaryOrdersTEST.php?page=$i">$i</a> <?php } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; ?> <a href="StationaryOrdersTEST.php?page=$pagenext\">NEXT".$limit."</a> <?php }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> Any help would be brilliant. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88406-pagination-help/ Share on other sites More sharing options...
sasa Posted January 29, 2008 Share Posted January 29, 2008 part while($row = mysql_fetch_array($result)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } echo("<tr bgcolor=".$bgcolor.">n<td>"); echo($row["URN"]); echo("</td>n<td>"); echo($row["productName"]); echo("</td>n</tr>"); } must be while($row = mysql_fetch_array($result)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } echo("<tr bgcolor=".$bgcolor.">\n<td>"); echo($row["URN"]); echo("</td>\n<td>"); echo($row["productName"]); echo("</td>\n</tr>"); } change line $pageprev = $page--; to $pageprev = $page-1; and line $pagenext = $page++; to $pagenext = ++$page; Quote Link to comment https://forums.phpfreaks.com/topic/88406-pagination-help/#findComment-452493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.