pagination problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinpkl
    New Member
    • Oct 2008
    • 41

    pagination problem

    hi all

    i m using pagination to show my products results according to particular category.
    it shows
    Code:
    PREV 1,2, NEXT
    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.

    Code:
    <?php
    $dealer_id=$_REQUEST['dealer_id'];
    $category_id=$_REQUEST['category_id'];
    $limit=3; // rows to return
    $qry="select * from product_table where dealer_id=$dealer_id";
    $result=mysql_query($qry);
    $row=mysql_fetch_array($result);
    $numrows=mysql_num_rows($result);
    
    // next determine if offset has been passed to script, if not use 0
    if (empty($offset)) {
        $offset=0;
    }
    
    // get results
    $qry="select * from product_table where dealer_id=$dealer_id limit $offset,$limit";
    $result=mysql_query($qry);
    
    // now you can display the results returned
    while ($row=mysql_fetch_array($result)) 
    {
    $desc = substr($row['detail_description'], 0, 250);
    	  echo "<tr>";
          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>";
          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>";
           echo "<td valign=top class='des' width=250>". $desc . "</td>";
           echo "</tr>";
      	  echo "<tr>";
    	 echo "<td valign=top colspan=3 align=right>". "<img src='http://localhost/vineet/images/view_details.gif' border=0 />" . "</td>";
    	  echo "</tr>";
    	  echo "<tr>";
    	  echo "<td class=shadow colspan=5>" . "<image src='http://localhost/vineet/images/spacer.gif' height=15 width=15>" . "</td>";
    	  echo "</tr>";
    }
    
    // next we need to do the links to other results
    
    if ($offset==0) { // bypass PREV link if offset is 0
        $prevoffset=$offset-1;
        print "<a href=\"products-10-1.html?offset=$prevoffset\">PREV</a> &nbsp; \n";
    }
    
    // calculate number of pages needing links
    $pages=intval($numrows/$limit);
    
    // $pages now contains int of pages needed unless there is a remainder from division
    if ($numrows%$limit) {
        // has remainder so add one page
        $pages++;
    }
    
    for ($i=1;$i<=$pages;$i++) { // loop thru
        $newoffset=$limit*($i-1);
        print "<a href=\"products-10-1.html?offset=$newoffset\">$i</a> &nbsp; \n";
    }
    
    // check to see if last page
    if (!(($offset/$limit)==$pages) && $pages!=1) {
        // not last page so give NEXT link
        $newoffset=$offset+$limit;
        print "<a href=\"products-10-1.html?offset=$newoffset\">NEXT</a><p>\n";
    }
    ?>
    vineet
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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

    Comment

    Working...