I have a query that outputs items details. Each item is associated with a category. There is a limit of results I can output, because I can only use a certain number of lines on a page.
When I print the results on the page I print a category name, as a title, just once above the items in that category.
Depending on the number of of items in each category I may end up with a different number of categories, which changes the number of lines on a page.
How do I count how many DISTINCT categories are in my results and adjust the LIMIT accordingly.
$sql = ("
SELECT * FROM myTable
WHERE memberID= ".$ID."
ORDER BY categoryID ASC ");
$limit = 20;
$myResults = $db->get_results($sql.$limit)
It seems like some sort of chicken and the egg problem. Above if what I currently have. It assumes there's only one category 20 + 1 = 21 lines. I need to be able to keep the same number of lines even if the number of the categories shown (unique) is different.