How many returned results have the same manufacturers
Posted: Sat Apr 10, 2010 1:04 pm
So here is the issue. I am running a query to return every item that is searched for using LIKE I then use a while statement to echo each row of the database one at a time. The variable $manufacturer returns well the manufacturer of the product. What I need is to display each individual manufacturer returned and how many items for each manufacturer.
So say HP (15), Epson (5), etc. This is how I'm currently thinking of going about doing this but there is probably a much more effective way to do this then how I'm going about it below. Even in my example I'm not sure how to do an incrementing variable variable. Still fairly new to php so any help is greatly appreciated! Also there is a lot of manufacturers so testing if it's one of each wouldn't work either.
Let me know if I'm being unclear about my problem.
So say HP (15), Epson (5), etc. This is how I'm currently thinking of going about doing this but there is probably a much more effective way to do this then how I'm going about it below. Even in my example I'm not sure how to do an incrementing variable variable. Still fairly new to php so any help is greatly appreciated! Also there is a lot of manufacturers so testing if it's one of each wouldn't work either.
Let me know if I'm being unclear about my problem.
Code: Select all
// Check if current manufacturer has already been found in previous item
If ($manufacturer = $existing_manufacturer1){
$existing_manufacturer1_count += 1
} elseif ($manufacturer = $existing_manufacturer2){
$existing_manufacturer2_count += 1
} else {
//if not found in a previous item then assign it to an incrementing variable
$manufacturer = $existing_manufacturer3
}
echo $existing_manufacturer1 . $existing_manufacturer1_count (etc etc);