473,763 Members | 2,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pagination problem

41 New Member
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
1 1148
nathj
938 Recognized Expert Contributor
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

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

Similar topics

2
2804
by: Kurzman | last post by:
Let me know what you think about the following code: DECLARE @MaxIdValue int DECLARE @MaxSortFieldValue nvarchar(50) SELECT TOP 1 @MaxIdValue = , @MaxSortFieldValue = FROM ( SELECT TOP PageNumber*RowsPerPage , FROM MyTable WHERE (FilterCondition) ORDER BY , ) T
2
2328
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't functioning or the $page variable isnt working in that part of the code... Below is the link to the working but broken page.. as well as the main part of my code... Hopefully someone can explain why the operators arent working or maybe see what i...
11
2782
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by going to url's like mywebsite/gallery.php?category=landscape Although the above worked perfectly...
0
1463
by: Sheau Wei | last post by:
I am using php version 4.3.3. The below was my pagination code. My problem is that when i run this code in my computer, i wall fail because of the hyperlink of the pagination not function when i click it. But when i run in other people computer, It was no problem at all. I wonder to know what wrong to my coding . Is it different version of php also reflect the output? <? //required file for database connection require("config.php");...
2
1858
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from table with pagination form data's are retaining if i select from first page but data not retaining if i select option from other than 1st page. i m using hidden field in pagination page. Thanks stalin
1
6851
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows links for all 8 pages. Previous 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 Next i want to...
16
2778
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
1
3555
markrawlingson
by: markrawlingson | last post by:
Hello, For starters: Yes, I am new to asp.net, however I hold a good 9-10 years of experience working with classic asp and am only just now upgrading my skills. I'm picking asp.net up pretty quickly but I'm running into a stumbling block that I just can't seem to get around. I think I know what the problem is, and I'm pretty confident in a work around, but it's not quite what I had hoped for so I thought I'd pick some of the experts brains...
4
3575
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank. I have seen people mention this problem, and they have been told that a variable is...
2
2593
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title>
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9992
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7364
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.