What is the principle of the relational number table? There is a query, but the query does not show?

assume that there is an item count table and use an item table
when I want to make an item list
I want to show an item table
the behavior of an item table
is to add this item to the goods store
but I am shopping. How can I show it?
I think of several methods
the first one is to enter the name of the item immediately after joining to the property list
, and then use the ID to purchase his product
, but in this way, if the information of the product is changed, all the merchandise will have to change it

.

the second way is to enter only the value
one is the ID, of the goods and the other is the ID
of the goods, but the ID of the goods includes the product name
, so how do I display the goods? The only data I can catch is ID, using ID
how can I turn off another table?
grab the merchandise table according to the commodity ID, and then display the commodity information?
in this way, there will be no source to modify the update of product information
but I don"t know how to show this method?

user has id
user_cart has prod_id, id
product has prod_id, name, icon

my mysql query is

SELECT b.icon, b.name FROM user_cart as c
      LEFT JOIN product AS b ON c.prod_id = b.id
      Where c.user_id= "{$_SESSION["user-id"]}"

or

SELECT b.* FROM product as b
      LEFT JOIN user_cart as c ON c.prod_id = b.prod_id
      LEFT JOIN user AS a ON a.id = c.id
      WHERE c.id = "{$_SESSION["user-id"]}"

pretend to be mysql structure

user_cart

clipboard.png

user

clipboard.png

product

clipboard.png



clipboard.png

the agent we show is:

<? while($row = mysqli_fetch_array($data)){?>
        <?=$row["name"];?>
      <?}?>

is there any trouble?

Mar.21,2021

the second is more appropriate. For simple design, merchandise ID, users ID, merchandise quantity is enough.
first request the API to get the user ID , which is the premise.
then according to the user ID , go to the shopping cart list to find all the corresponding merchandise ID .
finally go to Commodity list to find the corresponding merchandise according to the Commodity ID list.
is actually similar to the steps you described yourself.

SELECT * FROM user_cart as c
LEFT JOIN product AS b ON c.prod_id = b.prod_id
WHERE c.id = '{$_SESSION["user-id"]}'
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf1c90-46336.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf1c90-46336.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?