Database Search Engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
denewey
Forum Newbie
Posts: 9
Joined: Wed Mar 18, 2009 8:50 pm

Database Search Engine

Post by denewey »

I have a php database search engine that works great, only thing is all results display on one page. I'm trying to figure out a simple handling for breaking it down 20 results to a page without passing the db query results from page to page. Is there a way to formulate a sql query so it gives me the first 20 results, then the next 20 results, etc.? Or is there some other simple method. the only options I'm looking at right now are:
1. re-execute the sql query on each page and only display the results desired (i.e. if you want results 21 - 40 loop through the first 20 but don't display them...
OR
2. Save all results in an array and pass it page to page and display the desired results from that array.

I can't help but think there is a simpler method.
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: Database Search Engine

Post by kaszu »

Add LIMIT to the SQL query, it allows to select only number of rows with offset.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Database Search Engine

Post by califdon »

What you described is called "pagination". There are hundreds of tutorials and discussions on the topic. Just use that search term here in the forum and/or in a search engine.
denewey
Forum Newbie
Posts: 9
Joined: Wed Mar 18, 2009 8:50 pm

Re: Database Search Engine

Post by denewey »

Thank you for your answers. I think the "LIMIT" keyword will do nicely. That handles my problem.

- denewey
Post Reply