When the number of join data is also more than one, how to show it?

SELECT
          t.name AS tname
        FROM `product` as p
        JOIN
          `product_theme` as pt ON pt.prod_id = p.prod_id
        JOIN
          `theme` as t ON t.theme_id = pt.theme_id

theme
clipboard.png

product_theme
clipboard.png

product theme
product_theme prod_id

tname

while ($row...mysqli_fetch_array) $row["tname"] prod_id 41 theme

clipboard.png

so how do I show and rewrite it?

Mar.23,2021

according to your needs, you can use the group_concat function and display it in groups by prod_id. The SQL is similar to the following:

select proid_id,group_concat(t.name SEPARATOR ';') as tname from product as p .....  group by prod_id

the result is similar:

proid_id      tname
...
40            
41            ;
...

in this way, $orw ['tname'] in the program gets "the best warm bag in summer; the world of Komatsu Sinai", which can be divided into arrays with the explode function.

Menu