Jump to content

Why does my page always show JUST first set of results?


advancedfuture

Recommended Posts

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.