我有以下疑问:

$cuttinglist_products_query =
  tep_db_query("select op.orders_products_id, op.orders_id, op.products_id, ".
                      "op.products_model, op.products_name, op.products_quantity, ".
                      "p.products_id from " . TABLE_ORDERS_PRODUCTS . " op " .
                  " left join " . TABLE_PRODUCTS . " p " .
                  " on (op.products_id = p.products_id) where orders_id = '" .
                  (int)$cuttinglist['orders_id'] . "'");

这将两个具有相同id的表连接在一起。如何连接第三个表,称为:
"TABLE_ORDERS_PRODUCTS_ATTRIBUTES"

具有相同的id:
"TABLE_ORDERS_PRODUCTS"

使用的ID是:
"orders_products_id"

最佳答案

只需添加另一个连接子句:

SELECT ...
FROM TABLE_ORDERS_PRODUCTS op
LEFT JOIN TABLE_PRODUCTS p ON op.products_id = p.products_id
LEFT JOIN TABLE_ORDERS_PRODUCTS_ATTRIBUTES pa ON op.products_id = pa.orders_products_id
WHERE ...

关于php - 连接具有不同ID的多个表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12251313/

10-13 01:38