How I group by, with page numbering ?

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How I group by, with page numbering ?

Post by simonmlewis »

This is difficult to describe in a Subject.

We want to have a list of all products that are a specific type of product. Trouble is there are hundreds of them.
So we have them grouped into Categories and then Sub Categories. But means a very long slow-to-load page.

So I thought I would put them into page of 2 categories per page.

I've worked out the page number, but it's the actual page number links in the footer that don't work.

$query = "SELECT COUNT(catid) AS numrows FROM products WHERE top = 'yes' GROUP BY catid";
This is generating 66 pages. and it should only be about 5 or 6 pages.
If I run this in phpmyadmin, I see 9 rows, but each row has a few hundreds items in them.

So it maybe one of those queries in a query to make it work.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How I group by, with page numbering ?

Post by Celauran »

simonmlewis wrote:$query = "SELECT COUNT(catid) AS numrows FROM products WHERE top = 'yes' GROUP BY catid";
This is generating 66 pages. and it should only be about 5 or 6 pages.
If I run this in phpmyadmin, I see 9 rows, but each row has a few hundreds items in them.
Are the results you see in phpMyAdmin what you would expect? How are display and pagination working? Are you paginating items within a subcategory, or is pagination meant to navigate through subcategories (ie. page 1 is men's shirts, page 2 is men's pants, page 3 women's shirts, etc)? What queries are in play and what does the pagination code look like?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How I group by, with page numbering ?

Post by simonmlewis »

In the phpmyadmin results, I see each category idea, and then how many products are in each category. There are 9 rows of results.
I am paginating the categories. So if there are 20 categories, I want to show 3 categories per page.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: How I group by, with page numbering ?

Post by Celauran »

I don't see how you're getting 66 pages out of 9 rows. As I'm understanding it, you're doing to need two queries here; one for the categories (and pagination) and another for the actual contents of the page. Is it possible you're trying to paginate on that second result set?
Post Reply