I have the following query:
$myquery = mysql_query("SELECT p.name, GROUP_CONCAT(m.name) as products
FROM access as pm
INNER JOIN seller as p on p.id = pm.id_seller
INNER JOIN products as m on m.id = pm.id_product
WHERE p.id = '".$_COOKIE['id_seller']."'");
Which returns me this array:
Array (
[0] => Seller Name [name] => Seller Name
[1] => Product1 [products] => Product1
);
How should I query the database correctly? Thanking in consideration that I have 3 tables (products, access and seller). What I’d like to achieve is to attribute (access) one or more products to a seller.
And how my drop-down list populate code would look like?
<?php
echo'<select name="productaccess">';
foreach($myquery as $product) {
echo'<option value="'.$product.'">'.$product.'</option>';
}
echo'</select>';
?>
Thanks!
If you want the products for just one seller, you don’t need grouping at all. Just list the names of the products:
Now
$myqueryis only a resource identifier, not the results, so you get the latter withmysql_fetch_array()like this: