473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

limit search results so that there is a "Next 10" and "Previous 10"?

Hi there...

How can I limit search results so that there is a "Next 10" and "Previous 10"?

thanks for any reply....
Apr 18 '08 #1
1 1639
Atli
5,058 Expert 4TB
Hi. Welcome to Bytes!

After trying, and failing, to explain this a few times, I feel a simple code example will be more helpful :)

Consider this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get the current page index, sent thought the URL
  3. $pageIndex = @$_GET['pindex'];
  4.  
  5. // If there was no index in the URL, set it to 0
  6. if(empty($pageIndex))
  7.   $pageIndex = 0;
  8.  
  9. // Set some basic variables needed throughout the script
  10. $amountPerPage = 10;
  11. $nextPage = $pageIndex + 1; // The number for the Next link
  12. $prevPage = $pageIndex - 1; // The number for the Prev link
  13. $firstItem = $pageIndex * $ammountPerPage;
  14.  
  15. // Get the data from where ever you get you data from
  16. // ... compact MySQL example 
  17. $result = mysql_query("SELECT field FROM table LIMIT {$firstItem}, {$ammountPerPage}");
  18.  
  19. // Show the data
  20. // ... for example
  21. forech ($row = mysql_fetch_assoc($result)) {
  22.   echo "Field = ". $row['field'] ." <br />";
  23. }
  24.  
  25. // Show the Next and Prev links
  26. echo "<a href='?pindex={$prevPage}'>Previous {$ammountPerPage}</a> | 
  27.       <a href='?pindex={$nextPage}'>Next {$ammountPerPage}</a>";
  28. ?>
  29.  
The index of the page that is to be displayed is simply added to the URL as a GET variable, and then retrieved through the $_GET array. If there is no variable passed the page index will be set to 0 (the first page).

This piece of code is obviously pretty basic and will have to be improved and adjusted to your needs before it is put to use, but you get the idea.
Apr 18 '08 #2

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

Similar topics

8
by: joe | last post by:
Can anyone help me out by either telling me how to get to the result i need or by pointing me to some documentation about the following question: A certain query to a database give me eg 100...
2
by: John Smith | last post by:
I have more than 4,000 pieces of email in my Yahoo account. I would like to write a program to download them all. In order to write such a program, I need to know a few things. 1. After I fill...
1
by: midiweb01 | last post by:
Sorry for my bad english here! I try my best. I would like to make a slideshow for my site about paintings. I have four menus: Portraits-landscapes-Still Life-Animals Each Menu has his own...
10
by: Jude | last post by:
here is the source code: #include<stdio.h> int main() { float f; scanf("%f",&f); printf("The float is %10.5f\n",f); return 0; }
2
by: ntsNews | last post by:
Hi, Using the built in command "Find Next" is there a way to have the Match Drop Down Menu to default to "Start of Field"... or can it be the only option? GCM
5
by: Nick Gilbert | last post by:
Hi, I'm using the asp:Wizard control and on some of the steps, I would only like the user to be able to progess to the next step by clicking an image button. Therefore I would like to be able to...
10
by: craig.keightley | last post by:
I am trying to get the next row within a loop for a script i am developing... I need to display a final table row within the table that i have displayed on the page, but i only want to show it...
1
by: Jeff | last post by:
I need to place a "Previous Page" link on every page within my site and a simple javascript:history.back() will not work because I need it to capture the state of the page when I left it. For...
3
by: karen987 | last post by:
Can someone please explain what code i need to add to keep a set of links at the bottom of a pop up window? I need it in a page where people post comments. It is a pop up window, of about 500x400...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.