Ltj_bukem Posted December 3, 2007 Share Posted December 3, 2007 Hi, I have a simple query that returns a set of results using pagination. It basically checks a table that contains every name, date and index of pdf's they have downloaded. However, I have set a limit of 10 results per page but for some reason the first page displays all of the results, as does the second page, third page and so on. Here's the code <?php $pagenum = $_GET['pagenum']; if (isset($_SESSION['valid_user']) ) { $username=$_SESSION['valid_user']; } else { $username=$_SESSION['valid_user']; } echo"username=$username"; echo "<br></br>"; mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } echo"pagenum=$pagenum"; $data = mysql_query("SELECT username,pdf_id,date,name FROM user_history WHERE username = '$username'")or die(mysql_error()); $rows = mysql_num_rows($data); echo "rows = $rows"; echo "<br></br>"; //This is the number of results displayed per page $page_rows = 11; //This tells us the page number of our last page $last = ceil($rows/$page_rows); $total_pages = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; echo "max =$max"; //This sets the query again, the same one... $data_p = mysql_query("SELECT username,pdf_id,date,name FROM user_history WHERE username = '$username'") or die(mysql_error()); //This is where you display your query results ?> </p16> <p16> <table border = "0" align = "center" > <tr> <th align='left' ><font size='2' font color = '#ffffff' >username</th> <th align='left' > <font size='2' font color = '#ffffff'>pdf_id</th> <th align='left' > <font size='2' font color = '#ffffff'>date</th> </tr> <?php echo"<br>"; echo"<br>"; while (list($username,$pdf_id,$date,$name) = mysql_fetch_array($data_p)) { echo "<tr >"; echo "<td width = '200' height = '1' align = 'left'><font size='2'font color = '#ffffff' face='Arial'>$username</td>"; //echo "<td width = '150' height = '1' align = 'left'><font size='2'font color = '#ffffff' face='Arial'>$pdf_id</td>"; //echo "<td width = '150' height = '1' align = 'left' ><font size='2'font color = '#ffffff' face='Arial'>$date</td>"; echo "</tr>"; } ?> </table> <br clear = "left"/> </p16> <?php if ($rows>10){ ?> <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%"> <tr> <td><hr noshade color="#FFFFFF" align="left" width="100%" size="2"> </td> </tr> <tr> <td align="center"> <p23> <?php include('paging2.php'); ?> </td> </tr> </table><br> <?php } ?> Can anyone see where I'm going wrong? Cheers Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 3, 2007 Share Posted December 3, 2007 how do you limit your query i dont see it in your query ? Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 Your code is terribly difficult to follow because of a distinct lake of indentation, but I don't see any LIMIT clause in any of your queries. Quote Link to comment Share on other sites More sharing options...
Ltj_bukem Posted December 3, 2007 Author Share Posted December 3, 2007 Cheers fellas, I forgot to put LIMIT into the query, which was stored as the $max variable. thanks Quote Link to comment 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.