advancedfuture Posted March 20, 2007 Share Posted March 20, 2007 Whenever I execute a query I limit it to lets say 2 rows per page. The problem is my code will only say there is 1 page of results when there should be more! What am I doing wrong? <? //GET FORM DATA $section = $_POST['section']; $category = $_POST['category']; require("connect.php"); //CONNECT TO THE DATABASE //DETERMINE PAGE WE ARE ON if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if //GET DATABASE RESULTS BASED ON CATEGORY PICKED AND SORT ROWS $result = mysql_query("select * from upload where category = '$category'"); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; $rows_per_page = 2; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno < 1) { $pageno = 1; } elseif ($pageno > $lastpage) { $pageno = $lastpage; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $result2 = mysql_query("select * from upload where category = '$category' $limit"); //FETCH SQL DATA AND PRINT IT TO THE SCREEN while($row = mysql_fetch_array($result2)){ $id = $row["id"]; $codes = $row["codes"]; print '<table width="400" border="2" cellspacing="0" cellpadding="0">'; //DISPLAY THUMBNAIL IMAGE FROM DATABASE print ("<tr><td><img src=\"download.php?id=$id\"></td></tr>"); //POPULATE TEXTFIELD WITH CSS CODE FOR TEMPLATE print "<tr><td><textarea name='textfield' wrap='OFF' cols='50' rows='7'>".$codes."</textarea></td></tr>"; print '</table><br /><br />'; } //CREATE HYPERLINKS TO PREVIOUS PAGES if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> "; } // if //SHOW WHAT PAGE WE ARE ON echo " ( Page $pageno of $lastpage ) "; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> "; } // if ?> Link to comment https://forums.phpfreaks.com/topic/43580-why-does-my-page-always-show-just-first-set-of-results/ Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 The probs is with the limit calc limit=(rows per page* pageno)-rows per page , rows per page Link to comment https://forums.phpfreaks.com/topic/43580-why-does-my-page-always-show-just-first-set-of-results/#findComment-211648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.