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. 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.
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. 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' ";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.