Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 非唯一表/别名:';产品';_Php_Mysql_Inner Join - Fatal编程技术网

Php 非唯一表/别名:';产品';

Php 非唯一表/别名:';产品';,php,mysql,inner-join,Php,Mysql,Inner Join,大家好,这是我第一次处理内部连接,所以非常感谢任何帮助 INNER JOIN products AS products ON orders.product = products.ID INNER JOIN products AS products ON orders.product2 = products.ID 只是想知道为什么我从我创建的代码中得到以下错误: 非唯一表/别名:“产品” 以下是代码本身: mysql_select_db($database_reps, $reps); $quer

大家好,这是我第一次处理内部连接,所以非常感谢任何帮助

INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN products AS products ON orders.product2 = products.ID
只是想知道为什么我从我创建的代码中得到以下错误:

非唯一表/别名:“产品”

以下是代码本身:

mysql_select_db($database_reps, $reps);
$query_orders = sprintf("SELECT
orders.ID AS mainID,
customers.`Name` AS customerName,
products.ProductName AS product,
orders.Quantity AS Quantity,
orders.comment As comment,
orders.SalesPrice AS SalesPrice,
orders.Price AS Price,
orders.paid AS paid,
orders.product2 AS product2,
orders.AgeOfPayment AS AgeOfPayment,
orders.orderDate AS orderDate,
products.Price AS productPrice,
staff.StaffName AS staffMember,
orders.bonus AS bonus
FROM
orders
INNER JOIN staff AS staff ON orders.staffMember = staff.ID
INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN products AS products ON orders.product2 = products.ID
INNER JOIN customers AS customers ON orders.customerName = customers.ID
WHERE
orders.ID = %s", GetSQLValueString($colname_orders, "int"));

$orders = mysql_query($query_orders, $reps) or die(mysql_error());
$row_orders = mysql_fetch_assoc($orders);
$totalRows_orders = mysql_num_rows($orders);
加入证明有点困难,但任何帮助都非常感谢

INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN products AS products ON orders.product2 = products.ID
产品
表的两个联接都被别名为
产品
,为每个联接使用不同的别名,如
产品1
产品2
;并确保在所选列列表中使用正确的别名;虽然你的选择列表并没有给出你想要参考的任何指示

编辑

SELECT orders.ID AS mainID,
       customers.`Name` AS customerName,
       products1.ProductName AS productName1,
       products2.ProductName AS productName2,
       orders.Quantity AS Quantity,
       orders.comment As comment,
       orders.SalesPrice AS SalesPrice,
       orders.Price AS Price,
       orders.paid AS paid,
       orders.product2 AS product2,
       orders.AgeOfPayment AS AgeOfPayment,
       orders.orderDate AS orderDate,
       products1.Price AS productPrice1,
       products2.Price AS productPrice2,
       staff.StaffName AS staffMember,
       orders.bonus AS bonus
  FROM orders
 INNER JOIN staff
    ON orders.staffMember = staff.ID
 INNER JOIN products AS products1 
    ON orders.product = products1.ID
 INNER JOIN products AS products2 
    ON orders.product2 = products2.ID
 INNER JOIN customers 
    ON orders.customerName = customers.ID
 WHERE orders.ID = ...
产品
表的两个联接都被别名为
产品
,为每个联接使用不同的别名,如
产品1
产品2
;并确保在所选列列表中使用正确的别名;虽然你的选择列表并没有给出你想要参考的任何指示

编辑

SELECT orders.ID AS mainID,
       customers.`Name` AS customerName,
       products1.ProductName AS productName1,
       products2.ProductName AS productName2,
       orders.Quantity AS Quantity,
       orders.comment As comment,
       orders.SalesPrice AS SalesPrice,
       orders.Price AS Price,
       orders.paid AS paid,
       orders.product2 AS product2,
       orders.AgeOfPayment AS AgeOfPayment,
       orders.orderDate AS orderDate,
       products1.Price AS productPrice1,
       products2.Price AS productPrice2,
       staff.StaffName AS staffMember,
       orders.bonus AS bonus
  FROM orders
 INNER JOIN staff
    ON orders.staffMember = staff.ID
 INNER JOIN products AS products1 
    ON orders.product = products1.ID
 INNER JOIN products AS products2 
    ON orders.product2 = products2.ID
 INNER JOIN customers 
    ON orders.customerName = customers.ID
 WHERE orders.ID = ...

嗨,马克,谢谢你。我只是对布局有点好奇。你能给我举个例子说明你的意思吗?你想在你选择的栏目列表中看到哪个产品名称和价格?与orders.product匹配的名称/价格,还是与orders.product2匹配的名称/价格?或者两者都有?@草莓我将其更改为:内部连接产品作为订单上的产品。产品=产品。ID内部连接产品作为订单上的产品2。产品2=产品。ID返回时没有错误,但我有一个示例:$product=$row_orders['product']$product2=$row_订单['product2'];当我回显产品2时,我得到nothing@MarkBaker嗨,马克,我输入了那个编辑,但当我回显$product2时,我仍然只返回它的ID。我这样列出它:
$product2=$row\u orders['product2']是,
product2
将向您显示id,因为它是
订单。product2
值。。。您需要查看$row\u订单['productName1']和$row\u订单['productName2']以及$row\u订单['productPrice1']和$row\u订单['productPrice2']Hi Mark,谢谢。我只是对布局有点好奇。你能给我举个例子说明你的意思吗?你想在你选择的栏目列表中看到哪个产品名称和价格?与orders.product匹配的名称/价格,还是与orders.product2匹配的名称/价格?或者两者都有?@草莓我将其更改为:内部连接产品作为订单上的产品。产品=产品。ID内部连接产品作为订单上的产品2。产品2=产品。ID返回时没有错误,但我有一个示例:$product=$row_orders['product']$product2=$row_订单['product2'];当我回显产品2时,我得到nothing@MarkBaker嗨,马克,我输入了那个编辑,但当我回显$product2时,我仍然只返回它的ID。我这样列出它:
$product2=$row\u orders['product2']是,
product2
将向您显示id,因为它是
订单。product2
值。。。您需要查看$row\u订单['productName1']和$row\u订单['productName2']以及$row\u订单['productPrice1']和$row\u订单['productPrice2']