Hi guys
I am trying to figure out how to add information to each product I am displaying. I have this query to start with:
$result = mysqli_query($link, "SELECT products.*, company.companyname FROM products INNER JOIN company ON products.companyid=company.id WHERE product.availability='In Stock' ORDER BY company.companyname, products.productname");
if (!$result)
{
$error = 'Error.';
$link = '.';
include 'error.php';
exit();
}
And I am displaying the data with this:
$groups = array();
while ($row = mysqli_fetch_assoc($result)) {
$groups[ $row['companyname'] ][] = $row;
}
foreach ($groups as $companyname => $productnames) {
echo "<strong>"; echo "$companyname\
"; echo "</strong>";
echo "</br>";
foreach ($productnames as $productname) {
echo "$productname[productname]\
";
echo "</br>";
}
echo "</br>";
}
This works and is giving me the following output:
COMPANY
productname_1
productname_2
ANOTHER COMPANY
productname_1
productname_2
But my question is, how can I, on top of that, have each product as a “sub group” - showing additional information on each product, such as colour/size etc (all attributes from the same ‘products’ table I am using already).
My goal is to have the layout like this (each product a separate div for styling):
COMPANY
[Product 1 thumbnail] | product name, colour, any other attributes etc |
[Product 2 thumbnail] | product name, colour, any other attributes etc |
NEXT COMPANY
[Product 1 thumbnail] | product name, colour, any other attributes etc |
[Product 2 thumbnail] | product name, colour, any other attributes etc |
Appreciate any tips.