473,387 Members | 1,691 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,387 software developers and data experts.

How to limit no of items to be displayed per page?

Dear all,
I am new to PHP and Mysql, and have created a table in Mysql to store product details and have written a form to upload product details (Title, image url, description, download link, and product rights) through admin section in PHP,
The problem is if i have entered 50 items and when i call db from members area all items are displayed on the same page, How can i restrict no of items to be displayed as 10, and automatically display url for 5 pages at bottom of page, i.e when i upload more products (say now the total is 70) no of pages will also increment automatically. (in this case will be 7 and say when user clicks on say 5 the product will be displayed from 41 to 50)

Please Guide.

Thanxs in advance,

Best Regards,
Ritesh Jain
Mar 5 '08 #1
5 2125
ronverdonk
4,258 Expert 4TB
There are numerous code sets and tutorials about MySQL results pagination on the web. Google for 'mysql results pagination' and you can pick the one you prefer.

Ronald
Mar 5 '08 #2
coolsti
310 100+
For the real answer as the moderator said, you should look for examples on the net, but maybe a few words here could help get you in the right direction.

The way I do this is via a combination of PHP scripting and making use of the capabilities of MySQL. The trick is to push as much of the task of this kind of bookkeeping to MySQL.

You limit the number of rows returned by MySQL in a query using the LIMIT clause at the end of the query. This has the form LIMIT 25 or LIMIT 50,25 which here respectively means return the first 25 rows found and return 25 rows found starting from the 51st row found (skipping the first 50 rows). The numbers that are actually used can be made to depend on how many results are to be shown per page and what page the viewer should be looking at.

To get how many pages actually are available for the user to choose from, you also need to know how many rows would have been returned if the limit clause was not used at all. You can get this information by including in the query statement the keyword SQL_CALC_FOUND_ROWS which should be placed just after the SELECT keyword. This slows the query down slightly, but gives you the information you need. You access this in PHP with another query:

SELECT FOUND_ROWS

which you make immediately after the main query.

The rest is up to you to find out via a search for example code, namely how to then create the HTML that takes this information and makes buttons or links that allow the user to select other pages of results.

Steve, Denmark
Mar 5 '08 #3
ronverdonk
4,258 Expert 4TB
Good explanation, Steve.

Ronald
Mar 5 '08 #4
Hi!
Thanxs Ronald for providing me the correct word for the same.
Thanxs Steve for explaining the same in such a simple language, i got a clear idea on how to do the same.

Thanxs once again for guiding,

Best Regards,
Ritesh Jain
Mar 5 '08 #5
ronverdonk
4,258 Expert 4TB
You are always welcome here. Success and see you some time.

Ronald
Mar 5 '08 #6

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

Similar topics

6
by: middletree | last post by:
Yesterday, I posted a question which ended up giving me a lot of info, but the core question never got answered/solved. The short version is that when a page displays a number of records based on...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
8
by: todd.freed | last post by:
Hey all, I have been racking my brain all morning to find a solution to this, and I am having no luck. Our webpage is created with Visual Studio C# and ASP.Net, hosted in-house using HTTPS with...
0
by: Barb | last post by:
How can I limit the number of items that show up in a dropdown list at one time? I have a list of states, and because my dropdown list is near the bottom of the page, it becomes a drop-up list. ...
0
by: jojobar | last post by:
We are using the ASP:Menu control (horizontal) for site navigation. The menu is contained by a table with css styles that allows us to give the illusion of a menu bar that runs the entire width of...
4
by: Derty | last post by:
Any way to limit the length of databound text on a datalist itemtemplate?
1
by: renahkw | last post by:
How can I easily limit the amount of rows displayed in a table, and then navigate from page to page? Each row consists of 3 cells: the first, containing a varying number of images followed by some...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hi, friends, I am using C#.net 2005 to create a windows application. It has menu items, such as File, etc. Under File, there are more menu items, such as New Files, Working Files, etc. Under...
4
dlite922
by: dlite922 | last post by:
hey guys, I'm doing some brain storming and getting ideas to come up with a solution. I have a list of ....data... that is displayed 10 per page with the LIMIT clause. Simply put: My...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.