public function selectAllProductsByCatID($catID){
$sql = "SELECT tbl_products.*, brands.brandCount
FROM tbl_products INNER JOIN (
SELECT brand, count(brand) AS brandCount
FROM tbl_products
GROUP BY brand
) AS brands ON tbl_products.brand = brands.brand
WHERE
catID = $catID
AND deleted = 0
ORDER BY brand, name";
$result = mysql_query($sql) or die(mysql_error());
return $result;
}
What i want to do is check the brand of a product. You can see a typical page here.
Notice the line “brandCount is 31” and “brandCount is 2”, this retuns the number of rows but it should be ONE, I think i need to change the SQL so it groups by brand? I did try doing this as you can see in my sql above but it doesnt work. Or should i use LIMIT?
There are many different types of Wines: Aromatic, Aromatic Magnum, Blended etc…
You can see these by scrolling down the page, they are displayed in subheadings which is perfect and exactly how i want it. However if you then look at this page:
So the reason why i tried doing this: if($row[‘brandCount’] > 1) is because i wanted to check to see if there was only one type of “brand” and if not show the name of the brand.