[英]I am getting following error while running my code
While I am running this code it showing me a following error:- 当我运行此代码时,它向我显示以下错误:-
Column 'virtuemart_product_id' in where clause is ambiguous Can anyone tell me how to resolve it. where子句不明确的列“ virtuemart_product_id”,谁能告诉我如何解决它。 Thank you.
谢谢。
<?php
mysql_connect('localhost','root','');
mysql_select_db('joom');
$get=$_GET['virtuemart_product_id'];
$get1=$_GET['virtuemart_category_id'];
$sql="SELECT
btn9c_virtuemart_products_en_gb.virtuemart_product_id,
btn9c_virtuemart_products_en_gb.product_s_desc,
btn9c_virtuemart_products_en_gb.product_desc,
btn9c_virtuemart_products_en_gb.product_name,
btn9c_virtuemart_product_prices.product_price
FROM btn9c_virtuemart_products_en_gb
JOIN btn9c_virtuemart_product_prices ON
btn9c_virtuemart_products_en_gb.virtuemart_product_id=btn9c_virtuemart_product_prices.virtuemart_product_id
WHERE virtuemart_product_id='$get' ";
if($result=mysql_query($sql))
{
while($row=mysql_fetch_assoc($result))
{
echo $row['product_price'];
}
}
else
{
echo (mysql_error());
}
?>
Put table name (or alias) with column names in where
clause which are common between tables you are joining. 将表名称(或别名)和列名称放在您要连接的表之间通用的
where
子句中。
Try below: 请尝试以下方法:
$sql="SELECT
btn9c_virtuemart_products_en_gb.virtuemart_product_id,
btn9c_virtuemart_products_en_gb.product_s_desc,
btn9c_virtuemart_products_en_gb.product_desc,
btn9c_virtuemart_products_en_gb.product_name,
btn9c_virtuemart_product_prices.product_price
FROM btn9c_virtuemart_products_en_gb
JOIN btn9c_virtuemart_product_prices ON
btn9c_virtuemart_products_en_gb.virtuemart_product_id=btn9c_virtuemart_product_prices.virtuemart_product_id
WHERE btn9c_virtuemart_products_en_gb.virtuemart_product_id='$get' ";
In your where
clause the property virtuemart_product_id
is not identified unambiguously by a table name. 在您的
where
子句中,表名不会明确标识属性virtuemart_product_id
。 Just use the table prefix there as well. 只需在那里也使用表前缀。
SELECT
prod.virtuemart_product_id,
prod.product_s_desc,
prod.product_desc,
prod.product_name,
prices.product_price
FROM btn9c_virtuemart_products_en_gb prod
JOIN btn9c_virtuemart_product_prices prices ON
prod.virtuemart_product_id=prices.virtuemart_product_id
WHERE prod.virtuemart_product_id='$get'
Btw use aliases for the tablenames. 顺便说一句,表名使用别名。 Saves a lot of typing and makes things more readable.
节省了大量的打字时间,并使内容更具可读性。
只需将表名添加到查询的WHERE部分:
..."WHERE table_you_need.virtuemart_product_id='$get' ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.