Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I restrict my results to 10 a page?

Status
Not open for further replies.

newphpbie

Programmer
Oct 17, 2003
110
GB
OK, without posting a load of code, I've been trying to find something on this for a while now and I haven't got anywhere.

All I want to do is limit the results displayed to a number (10) and have links to view the next 10 etc...

I've only found one site which sort of explains this but it was far to heavy for the simple task I want....

Could someone point me in the direction of a good tutorial for this topic please??
 
In general, you would write a script that produces output of 10 links. But which 10 links would be determined by a GET-method input called "page".

If the script is not given a page number, it would just output the first 10 links and a link the href of which is "yourscript.php?page=2".

If your script is given $_GET['page'], it can then output a block of 10 links based on that value. Gotchas are making sure that the page value is not out of bounds (if you have 30 links a page value of 100 is meaningless), and making sure that it prints links to the next page and previous page as necessary.

But the question is, what is the source of your link data? If it's a MySQL database, I recommend that you use the above suggestion in conjunction with the LIMIT clause of a SELECT statement.

If it's an array, it'll be some array index math.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Depending on the query each time you navigate another 10 rows you will hit the database, if its a hard query it will take time. Condier caching the results from the first query into a temp table or a local flat file(fast but not very scaleable) and read from that.
Its not hard to do 10 at a time, in fact see it as an interesting experiment.

Kevin
 
Querying the database is probably the best solution in SQL u can put the LIMIT

SELECT * FROM `myTable` LIMIT 0,30

Rocco is the BOY!!

SHUT YOUR LIPS...
ROCCOsm.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top