By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,229 Members | 469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,229 IT Pros & Developers. It's quick & easy.

pagination problem

P: 41
hi all

i m using pagination to show my products results according to particular category.
it shows
Expand|Select|Wrap|Line Numbers
  1. PREV 1,2, NEXT
  2.  
but when i click these links then these links dont show next and prev results of particular category i m on.

Like i m on nokia category. Then on clicking the next buton or prev buton , these butons show result of samsung or lg which are my prev and next categories.

i want to show results of next and prev products in nokia category.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dealer_id=$_REQUEST['dealer_id'];
  3. $category_id=$_REQUEST['category_id'];
  4. $limit=3; // rows to return
  5. $qry="select * from product_table where dealer_id=$dealer_id";
  6. $result=mysql_query($qry);
  7. $row=mysql_fetch_array($result);
  8. $numrows=mysql_num_rows($result);
  9.  
  10. // next determine if offset has been passed to script, if not use 0
  11. if (empty($offset)) {
  12.     $offset=0;
  13. }
  14.  
  15. // get results
  16. $qry="select * from product_table where dealer_id=$dealer_id limit $offset,$limit";
  17. $result=mysql_query($qry);
  18.  
  19. // now you can display the results returned
  20. while ($row=mysql_fetch_array($result)) 
  21. {
  22. $desc = substr($row['detail_description'], 0, 250);
  23.       echo "<tr>";
  24.       echo "<td width=115 valign=top class=bord align=center>" ."<img width=92 border=0 height=115 src='http://localhost/vineet/graphics/" . $row['image'] . "'/>" . "</td>";
  25.       echo "<td valign=top  width=150>". $row['product_name'] ."<br><br><br>". "Cutout Price"."<br>"."<span class='cut'>".$row['cutout_price']."</span>"."<br><br>". "Price"."<br>"."<span class='price16'>"."NZ$ ".$row['price']."</span>"."</td>";
  26.        echo "<td valign=top class='des' width=250>". $desc . "</td>";
  27.        echo "</tr>";
  28.         echo "<tr>";
  29.      echo "<td valign=top colspan=3 align=right>". "<img src='http://localhost/vineet/images/view_details.gif' border=0 />" . "</td>";
  30.       echo "</tr>";
  31.       echo "<tr>";
  32.       echo "<td class=shadow colspan=5>" . "<image src='http://localhost/vineet/images/spacer.gif' height=15 width=15>" . "</td>";
  33.       echo "</tr>";
  34. }
  35.  
  36. // next we need to do the links to other results
  37.  
  38. if ($offset==0) { // bypass PREV link if offset is 0
  39.     $prevoffset=$offset-1;
  40.     print "<a href=\"products-10-1.html?offset=$prevoffset\">PREV</a> &nbsp; \n";
  41. }
  42.  
  43. // calculate number of pages needing links
  44. $pages=intval($numrows/$limit);
  45.  
  46. // $pages now contains int of pages needed unless there is a remainder from division
  47. if ($numrows%$limit) {
  48.     // has remainder so add one page
  49.     $pages++;
  50. }
  51.  
  52. for ($i=1;$i<=$pages;$i++) { // loop thru
  53.     $newoffset=$limit*($i-1);
  54.     print "<a href=\"products-10-1.html?offset=$newoffset\">$i</a> &nbsp; \n";
  55. }
  56.  
  57. // check to see if last page
  58. if (!(($offset/$limit)==$pages) && $pages!=1) {
  59.     // not last page so give NEXT link
  60.     $newoffset=$offset+$limit;
  61.     print "<a href=\"products-10-1.html?offset=$newoffset\">NEXT</a><p>\n";
  62. }
  63. ?>
  64.  
vineet
Dec 16 '08 #1
Share this Question
Share on Google+
1 Reply

nathj
Expert 100+
P: 938
Hi vineet,

I notice your SQL query is working on the dealer ID as stored in the $_RQUEST[] array, as an aside it's better to be specific, use $_GET for variables in the query string and $_POST for submitted variables.

I recommend echoing the SQL statement so you can see what the SQL is when you first visit the page and what it is when you click next. This should give you some clue as to what is happening with the SQL.

Cheers
nathj
Dec 16 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.