Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql SELECT from 2 table
    text
    copied!<p>I can't seem to figure out how to make a SELECT statement that group products and displays the products under one product type.</p> <p>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. </p> <p>Example:</p> <pre><code>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 </code></pre> <p>What I want is to is the products to be displayed under a product group with 1 product image</p> <pre><code>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 </code></pre> <p>I hope someone is able to help me!</p> <p>EDIT</p> <p>I used your first example which works flawlessly. This is my final code:</p> <pre><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"); </code></pre> <p>and then my while loop:</p> <pre><code>$counter = 0; while($row = mysql_fetch_array($sql)) { $delimiter = "|"; $descr = explode($delimiter, $row["descr"]); $fname = explode($delimiter, $row["fname"]); $markers["###FLOOR###"] .= '&lt;div style="float: left; width: 200px; height: 425px; margin: 0px 10px 0px 10px; vertical-align: text-top; text-align: left;"&gt;'; $markers["###FLOOR###"] .= '&lt;p&gt;&lt;a href="index.php?page=sfp&amp;room='. $_GET["room"] .'&amp;floor='. $row["floorname"] .'&amp;wall='. $_GET["wall"] .'&amp;envi='. $_GET["envi"] .'&amp;fpanel='. $_GET["fpanel"] .'"&gt;&lt;img src="images/floors/'. $row["prodimage"] .'.jpg" width="200" /&gt;&lt;/a&gt;&lt;/p&gt;'; for ($i = 0; $i &lt; count($descr); $i++) { $markers["###FLOOR###"] .= '&lt;p&gt;&lt;a href="index.php?page=sfp&amp;room='. $_GET["room"] .'&amp;floor='. $fname[$i] .'&amp;wall='. $_GET["wall"] .'&amp;envi='. $_GET["envi"] .'&amp;fpanel='. $_GET["fpanel"] .'"&gt;'. $descr[$i].'&lt;/a&gt;&lt;/p&gt;'; } $markers["###FLOOR###"] .= '&lt;/div&gt;'; if (++$counter % 4 == 0) { $markers["###FLOOR###"] .= '&lt;div style="clear: both;"&gt;&amp;nbsp;&lt;/div&gt;'; } } </code></pre> <p>gives me exactly what I was looking for!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload