474,120 Members | 13,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Pagination code

10 New Member
The only problem I'm having with this code is when there are no values returned for the query, it is still allowing you to see and click the 'Next>>'. It disappears when there is at least one return on the search, but when there is none, it shows up. Here is where I got the source code from and of course the forum is 404'd. They're code has the exact same problem as my modified code.

http://www.designplace.org/scripts.php?page=1&c_id=25

my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.   // Get the search variable from URL
  4.  
  5.   $var = @$_GET['KEYWORDS'] ;
  6.   $trimmed = trim($var); //trim whitespace from the stored variable
  7.  
  8. // rows to return
  9. $limit=8; 
  10.  
  11.  
  12. // check for a search parameter
  13. if (!isset($var))
  14.   {
  15.   echo "<p>Our online inventory doesn't currently contain what you're looking for. Please visit a store for complete selection.</p>";
  16.   exit;
  17.   }
  18.  
  19. mysql_connect("sql002.choiceone.net","roomfulexpress","x47rkv7N"); //(host, username, password)
  20. mysql_select_db("roomfulexpress") or die("Unable to select database"); //select which database we're using
  21.  
  22. // Build SQL Query  
  23. $query = "select * from tblIndividualItem where KEYWORDS like \"%$trimmed%\"  
  24.   order by ITEM_NAME"; // EDIT HERE and specify your table and field names for the SQL query
  25.  
  26.  $numresults=mysql_query($query);
  27.  $numrows=mysql_num_rows($numresults);
  28.  
  29. // If we have no results, offer a google search as an alternative
  30.  
  31. if ($numrows == 0)
  32.   {
  33.   echo "<p>Our online inventory doesn't currently contain what you're looking for. Please visit a store for complete selection.</p>";
  34.   }
  35.  
  36. // next determine if s has been passed to script, if not use 0
  37.   if (empty($s)) {
  38.   $s=0;
  39.   }
  40.  
  41. // get results
  42.   $query .= " limit $s,$limit";
  43.   $result = mysql_query($query) or die("Couldn't execute query");
  44.  
  45. // display what the person searched for
  46. echo "<p>Search for:&nbsp;" . $var . "</p>";
  47.  
  48. // begin to show results set
  49. echo "<p>Results</p>";
  50. $count = 1 + $s ;
  51.  
  52.  
  53. // now you can display the results returned    
  54.   while ($row = mysql_fetch_array($result)) 
  55.  
  56.  
  57. {
  58. echo("<table>");
  59. echo("<tr>");
  60.     echo("<TD class=noOverflow width=150px><a href=itemprofile.php?SKU=". $row["SKU"] . " target=content> <img src= " . $row["TN"] . " alt=click to view profile /></a></TD>");
  61. echo("</tr>");
  62. echo("<tr>");
  63.     echo("<TD width=150px><h1> " . $row["ITEM_NAME"] . "</h1></TD>");
  64. echo("</tr>");
  65. echo("<tr>");
  66.     echo("<TD width=150px> $" . $row["ITEM_PRICE"] . "</TD>");
  67. echo("</tr>");
  68.     }
  69.  
  70.  
  71.     echo("</table>");
  72.  
  73.  
  74. $currPage = (($s/$limit) + 1);
  75.  
  76.  
  77.  
  78.   //Link to other results
  79.   echo("<div class=nextPrev>");
  80.   if ($s>=1) { // bypass PREV link if s is 0
  81.   $prevs=($s-$limit);
  82.   print "<p>&nbsp;<a href=\"$PHP_SELF?s=$prevs&KEYWORDS=$var\">&lt;&lt; 
  83.   Prev</a></p>";
  84.   }
  85.  
  86. // calculate number of pages needing links
  87.   $pages=intval($numrows/$limit);
  88.  
  89. // $pages now contains int of pages needed unless there is a remainder from division
  90.  
  91.   if ($numrows%$limit) {
  92.   // has remainder so add one page
  93.   $pages++;
  94.   }
  95.  
  96. // check to see if last page
  97.   if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
  98.  
  99.   // not last page so give NEXT link
  100.   $news=$s+$limit;
  101.  
  102.   echo "<p>&nbsp;<a href=\"$PHP_SELF?s=$news&KEYWORDS=$var\">Next &gt;&gt;</a></p>";
  103.   }
  104.  
  105. $a = $s + ($limit) ;
  106.   if ($a > $numrows) { $a = $numrows ; }
  107.   $b = $s + 1 ;
  108.   echo "<p>Showing items $b - $a of $numrows items</p>";
  109.   echo "</div>";
  110. ?>
Jul 27 '07 #1
2 2185
RoomfulExpress
10 New Member
http://www.roomfulexpr ess.com/newsite/php/item.php?KEYWOR DS=LIGHTING - this link shows you how it should work.

http://www.roomfulexpr ess.com/newsite/php/item.php?KEYWOR DS=BROKEN -
this shows you the 'Next >>'
Jul 27 '07 #2
kovik
1,044 Recognized Expert Top Contributor
Until you get the CODE tags into your post, I'm afraid that I'm not willing to waste time trying to read it. Sorry. However, I have written a tutorial on basic pagination in PHP that you may be interested in. I've also written a much more advanced class, but I've yet to write a tutorial for how it's made.
Jul 27 '07 #3

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

Similar topics

1
1775
by: Faree | last post by:
I am workign on a news portal which needs paginaiton as usual.but all the code i got depends on the number of records that will come from database :( .it is working well too. But i need pagination depends on the number of rows or number characters in a variable.for example if there are more than 100 characters in that it should be display with pagination code.could any one comeup with suggestios on this .
4
1343
by: Fernando Chilvarguer | last post by:
Hi, I've been trying to figure this one out for a while and I'm stalled. Here's my scenario: - a Parent window with a datagrid on it. The datagrid has pagination enabled and has an "Edit" link for each record. - Once someone clicks on the "Edit" link, a child window pops-up. The user edits the data and submits the form. All the server code is executed and
2
2349
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
2818
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
1476
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");...
1
1864
by: OceanBreeze | last post by:
I am new to .Net. I am using ASP 2.0 and C#. I want to pupolate a data grid programatically using the values obtained from a list conating domain objects. E.g., DAL.GetEmployee() returns a List of all Employee object. Each Employee object has two attributes (ID and Name). I drop a data grid control on ASP.Net Web form. Data grid will have 2 columns - one to display ID, another to display Name of employee.
0
1655
by: OceanBreeze | last post by:
I am using C# Page_Laod function to populate a web page with a table populated with several records. The table, rows (containing values) are popuated programatically with the values obtained from a list. I want to have pagination in that table control. My question: 1) Can it it done without writing any customn SQL code?
1
6863
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...
3
1336
oll3i
by: oll3i | last post by:
echo "<div id=\"join\">"; echo "<div id=\"main\">"; echo "<div id=\"contents\">"; echo "<div id=\"left_strip\">"; echo "<div id=\"content_table\">"; content here echo "</div>";
0
2936
by: George Ter-Saakov | last post by:
Trying to quickly create paginated grid. So i am using ListView. Unfortunatelly pagination works a little strange. Pagination control appears correctly. But when i click "2" page postback happens but current page is still first page. Then i click "3" page. Postback happens but current page is now "2" page. Then i click "4" page and again postback happens and page 3 becomes current. Why is that? How to make it work?
0
10700
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
10493
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
11757
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
12405
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
11280
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8895
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
6897
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5608
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
2
5089
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.