简体   繁体   English

PHP-MySQL 3表选择,更新,删除和插入与外键链接

[英]PHP-MySQL 3 tables select, update, delete and insert linked with Foreign Key

I have a problem with 3 InnoDB tables in MySQL linked with a foreign key, My tables are: 我在MySQL中有3个与外键链接的InnoDB表有问题,我的表是:

Table1 name - products

PID(PK, bigint, auto inc), 
CATALOG_NO, 
PRODUCT_NAME, 
COMPOSITION, 
SIZE, 
PRICE, 
SUBCAT_ID(foreign Key, index, bigint, keyname-FK_products_1)

Table2 name - subcategory

SUBCAT_ID(PKey, bigint, auto inc),
SUBCATEGORY_NAME, CAT_ID(fkey, bigint)


Table3 name - category

CAT_ID(Pkey, bigint, auot inc),
CAT_NAME

1.What is the right query to SELECT and list the data by joining 3 tables which should display result as: 1.什么是正确的查询以选择并通过联接3个表来列出数据,表应显示为:

ProductsPID, CATALOG_NO, PRODUCT_NAME, COMPO, SIZE, PRICE, SUBCATEGORY_NAME, CAT_NAME

2.What is the correct way to UPDATE and DELETE the above joined records by using one single query through one single form? 2.通过一种单一形式的单个查询来更新和删除上述联接记录的正确方法是什么?

3.Is it possible to insert the records also through single query by using single html form containing fields such as product name (input type=text), catalog no (input type=text), composition (input type=text), size (input type=text), price (input type=text), Choose subcategory (select type field with options), category (select type field with options) if yes then how? 3.是否可以通过使用包含产品名称(输入类型=文本),目录号(输入类型=文本),成分(输入类型=文本),大小(输入类型=文本),价格(输入类型=文本),选择子类别(选择带选项的类型字段),类别(选择带选项的类型字段),如果是,那么如何?

PLEASE HELP, ITS URGENT. 请帮助,它刻不容缓。

SELECT
  p.PID AS ProductsPID,
  p.CATALOG_NO, 
  p.PRODUCT_NAME, 
  p.COMPOSITION AS COMPO, 
  p.SIZE, 
  p.PRICE, 
  s.SUBCATEGORY_NAME,
  c.CAT_NAME
FROM products p
  INNER JOIN subcategory s
    ON p.SUBCAT_ID = s.SUBCAT_ID
  INNER JOIN category c
    ON s.CAT_ID = c.CAT_ID

update and delete can also use join in some cases (not on foreignkeys) but you probably only need to change the product table. 在某些情况下,update和delete也可以使用连接(不在外键上使用),但是您可能只需要更改产品表。 insert has to be on the individual tables. 插入必须在各个表上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM