Page 1 of 1

How I group by, with page numbering ?

Posted: Wed Sep 21, 2016 4:38 am
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.

Re: How I group by, with page numbering ?

Posted: Wed Sep 21, 2016 6:54 am
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?

Re: How I group by, with page numbering ?

Posted: Wed Sep 21, 2016 7:11 am
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.

Re: How I group by, with page numbering ?

Posted: Wed Sep 21, 2016 8:08 am
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?