Spliting results into pages

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
tnrh1
Forum Newbie
Posts: 14
Joined: Tue Nov 30, 2010 8:27 am

Spliting results into pages

Post by tnrh1 »

Hello everyone.
I have a page that filters products by character such as size,price etc..
I would like to split the results into pages 1,2,3 and so on.
I tried to do that but I failed, so I need you guys for that:
  • First of all I need to know how many results I have to calculate the amount of pages and that's a problem since I limit the query to 20 results.
    The solution I'm using is just sending another query without a limit and use the "mysql_num_rows" - if you have more efficient way to do that I would like to know.
As you see I'm struggling to solve it, any help will be very appreciated!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Spliting results into pages

Post by Celauran »

tnrh1 wrote:The solution I'm using is just sending another query without a limit and use the "mysql_num_rows" - if you have more efficient way to do that I would like to know.
SELECT COUNT
tnrh1
Forum Newbie
Posts: 14
Joined: Tue Nov 30, 2010 8:27 am

Re: Spliting results into pages

Post by tnrh1 »

Thanks!
What about the second part?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Spliting results into pages

Post by Celauran »

You've already got the links set up with all the necessary query string parameters. Just use a $page variable.

example.com/whatever.php?a=foo&b=bar&page=$page
Post Reply