I can’t seem to figure out how to make a SELECT statement that group products and displays the products under one product type.
I have a table called floors containing 15 different floor products and a table called floortypes containing 8 different product types (ftid) and a product image.
Each of the 15 products have a floortype which define which type it is. Some of the products are almost the same but with different measurements which but it gives the products a different description.
Example:
Product: Product 1 Product type: 1
Product: Product 2 Product type: 1
Product: Product 3 Product type: 2
Product: Product 4 Product type: 2
Product: Product 5 Product type: 3
Product: Product 6 Product type: 4
What I want is to is the products to be displayed under a product group with 1 product image
Producttype 1 image
Product 1 description
Product 2 description
Producttype 2 image
Product 3 description
Product 4 description
Producttype 3 image
Product 5 description
Producttype 4 image
Product 6 description
I hope someone is able to help me!
EDIT
I used your first example which works flawlessly.
This is my final code:
$sql = SQLHandling::SQLquery("SELECT A.fid, A.floorname, A.desc_dk, A.floortype, B.prodimage, GROUP_CONCAT(A.desc_dk SEPARATOR '|') AS descr, GROUP_CONCAT(A.floorname SEPARATOR '|') AS fname FROM floors A JOIN floortypes B ON A.floortype = B.ftid GROUP BY A.floortype, B.prodimage");
and then my while loop:
$counter = 0;
while($row = mysql_fetch_array($sql)) {
$delimiter = "|";
$descr = explode($delimiter, $row["descr"]);
$fname = explode($delimiter, $row["fname"]);
$markers["###FLOOR###"] .= '<div style="float: left; width: 200px; height: 425px; margin: 0px 10px 0px 10px; vertical-align: text-top; text-align: left;">';
$markers["###FLOOR###"] .= '<p><a href="index.php?page=sfp&room='. $_GET["room"] .'&floor='. $row["floorname"] .'&wall='. $_GET["wall"] .'&envi='. $_GET["envi"] .'&fpanel='. $_GET["fpanel"] .'"><img src="images/floors/'. $row["prodimage"] .'.jpg" width="200" /></a></p>';
for ($i = 0; $i < count($descr); $i++) {
$markers["###FLOOR###"] .= '<p><a href="index.php?page=sfp&room='. $_GET["room"] .'&floor='. $fname[$i] .'&wall='. $_GET["wall"] .'&envi='. $_GET["envi"] .'&fpanel='. $_GET["fpanel"] .'">'. $descr[$i].'</a></p>';
}
$markers["###FLOOR###"] .= '</div>';
if (++$counter % 4 == 0) {
$markers["###FLOOR###"] .= '<div style="clear: both;"> </div>';
}
}
gives me exactly what I was looking for!
Maybe you are just looking for this ?
This will give a resultset as follows,