我的 MySqli 数据库中有一个名为“产品”的表。
Products TABLE
product_id | INT primary KEY
product_name | VARCHAR(50)
product_price | float
通过 PHP,我在表产品中输入行,如下所示:
mysqli_query($con,"INSERT INTO products (product_id,product_name,product_price) VALUES
('$product_id','$product_name','$price')");
到目前为止,一切都运行良好。现在我想要第二个表称为“类别”,该表将包括产品可以拥有的所有可能的类别
类别表必须有一个category_id和一个category_name作为列
Category TABLE
category_id | INT primary KEY
category_name | VARCHAR(50)
我正在尝试找到一种将产品与 PHP 文件中的类别连接起来的方法
for example:
$get=mysqli_query($con, "SELECT * FROM `category`");
while ($row = mysqli_fetch_assoc($get)) {
echo $row['category_name']; //...here show all the categories
//...
//.. pick the category that the product belong
$category_Selected= .....;
}?>
..... And make the connection (with INSERT? or something) between product and category
我希望能够在产品表中进行搜索时(对于产品 X)显示它所属的类别(到目前为止我可以显示 Product_id、product_name 和 Product_price )
谢谢
最佳答案
关于php - 如何连接两个MySQL表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54617468/