Echo store name once with all the categories

241
May 12, 2017, at 5:50 PM

I have 3 tables interlinked with each other.

store_manufacture -------------- Categories -------------------------- Store_Categories

-----------------      --------------------          -----------------------
sm_id  | sm_name         cat_id | cat_name            sc_id|store_id|cat_id
-----------------      --------------------          -----------------------
12    | HP                 1    | Travel                1  |  12    |  1
                           2    | Health                2  |  12    |  2
                           3    | Electronics           3  |  12    |  3

I want to display storename once with all the category ids which i have to post to the next page.Here is a code i have tried:

php

 $cat_fetch=mysqli_query($con,"SELECT 
 sm_id,sm_brand_name,cat_id,sm_image,sm_link FROM `store_manufacture` sm 
 INNER JOIN store_category sc ON sc.store_id=sm.sm_id");
 while($row=mysqli_fetch_array($cat_fetch,MYSQLI_ASSOC){
 $id=$row['sm_id'];
 echo " <h5> <a href=''>" .$row['sm_brand_name']."   ". $row['cat_id']."</a></h5>";
 }

Output

Desired Output

HP (Travel, Health,Electronics)
Answer 1
"SELECT 
 sm.sm_name,GROUP_CONCAT(c.cat_name)  as cat_name FROM `store_manufacture` sm , Categories c, Store_Categories sc
where sm.sm_id = sc.store_id AND c.cat_id = sc.cat_id GROUP BY sm.sm_id";

this is query you should run hope this will help you

Rent Charter Buses Company
READ ALSO
I have 2 Questions or Queries

I have 2 Questions or Queries

I am new to php and MySQL and i have created several tables in my bd,

296
Is it possible to change default value of all table using SQL procedure?

Is it possible to change default value of all table using SQL procedure?

I need to change the default value of sql table fields from 'none' to 'null' where the datatypes are char varchar longtext etcAnd I want to keep the default value if its not 'none'

302
select all data on type , and change select if a row exists

select all data on type , and change select if a row exists

am new here so please redirect me if am posting this wrong sorry i can't post images yet

275
Merging two primary keys into one that has foreign keys MySQL

Merging two primary keys into one that has foreign keys MySQL

i have just collided with a problem on merging two primary keys into oneInformation:

270