Link to home
Start Free TrialLog in
Avatar of Ashraf-Hassan
Ashraf-HassanFlag for Netherlands

asked on

Display limited output from mysql query

I want to do the following:
1-The user search for certain item.
2-Server run sql search.
3-Display the output of the search by showing 25,50, or 100 output per page as per the user choice.
For number 1, and 2 I do that easily by php, but for number 3, I am not sure how to accomplish this, is server side or client to show only a selected number of output, can some guide me how to do so?
Avatar of Avinash Zala
Avinash Zala
Flag of India image

use LIMIT into the query. Like this:

$sql= 'SELECT * FROM table LIMIT 5';

will fetch only 5 first records.

$sql= 'SELECT * FROM table LIMIT 5 10';

will fetch 10 records starting from 5.

http://dev.mysql.com/doc/refman/5.1/en/select.html
http://hackmysql.com/case3

Hope this helps.
Addy
Avatar of Ashraf-Hassan

ASKER

The query part is not difficult, but the display part is not clear to me.
Let us say the search result return x output, and the use chose to see 25 output in one page, then depending on x will be the number of pages if x is 100 then we need 4 pages when the user press next he will to the next page, or if he press let us 3 he will jump to page 3.
Shall I make a full query, and put in an array and dsiplay it dynamically, or each time I need to make a query for each page.
Is there any example for that?
Ok, You want to use the pager.

Here is the link for that.

This will display page links based on the data.

http://pear.php.net/package/Pager/redirected

Hope this helps
Addy
ASKER CERTIFIED SOLUTION
Avatar of BenMorel
BenMorel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mehul_Panchal
Mehul_Panchal

use LIMIT into the query. Like this:

$sql= 'SELECT * FROM table LIMIT 5';

will fetch only 5 first records.

$sql= 'SELECT * FROM table LIMIT 5 10';

will fetch 10 records starting from 5.

Thanks
Mehul Panchal
Thank you BenMorel, your code is very helpful