Php 我在运行代码时遇到以下错误
当我运行此代码时,它显示以下错误:- where子句中的“virtuemart\u product\u id”列不明确 有人能告诉我怎么解决吗。 多谢各位Php 我在运行代码时遇到以下错误,php,mysql,Php,Mysql,当我运行此代码时,它显示以下错误:- where子句中的“virtuemart\u product\u id”列不明确 有人能告诉我怎么解决吗。 多谢各位 <?php mysql_connect('localhost','root',''); mysql_select_db('joom'); $get=$_GET['virtuemart_product_id']; $get1=$_GET['virtuemart_category_id']; $sql
<?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());
}
?>
在where
子句中放置表名(或别名)和列名,这在您要加入的表之间是通用的
请尝试以下内容:
$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' ";
在where
子句中,将表名(或别名)与列名放在一起,这在您要加入的表之间是通用的
请尝试以下内容:
$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' ";
在
where
子句中,属性virtuemart\u product\u id
未通过表名明确标识。也可以使用表前缀
选择
产品虚拟制造产品id,
产品说明,
产品说明,
产品名称,
产品价格
来自btn9c\u virtuemart\u产品\u en\u gb产品
加入btn9c_virtuemart_产品价格
prod.virtuemart\u product\u id=prices.virtuemart\u product\u id
其中prod.virtuemart\u product\u id='$get'
顺便说一句,表名使用别名。节省了大量的输入并使内容更具可读性。在
where
子句中,属性virtuemart\u product\u id
不是由表名明确标识的。也可以使用表前缀
选择
产品虚拟制造产品id,
产品说明,
产品说明,
产品名称,
产品价格
来自btn9c\u virtuemart\u产品\u en\u gb产品
加入btn9c_virtuemart_产品价格
prod.virtuemart\u product\u id=prices.virtuemart\u product\u id
其中prod.virtuemart\u product\u id='$get'
顺便说一句,表名使用别名。节省了大量的键入,使内容更具可读性。只需将表名添加到查询的WHERE部分:
..."WHERE table_you_need.virtuemart_product_id='$get' ";
只需将表名添加到查询的WHERE部分:
..."WHERE table_you_need.virtuemart_product_id='$get' ";
请告诉我们发生错误的代码/查询,否则我们只能猜测错误所在…可能是因为您使用的是join,并且在多个表中存在同名列。如果您可以显示查询,则可以向您建议一些解决方案。很好,请使用适当的代码语法。把标签放进去!同样,对于您的查询,php和mysql接受字符串中的换行符,但我在查询中选择了该列请告诉我们发生错误的代码/查询,否则我们只能猜测出错误的地方…可能是因为您在多个表中使用了join和,存在同名列。如果您可以显示查询,则可以建议您一些解决方案。请使用适当的代码语法。把标签放进去!同样,对于您的查询,php和mysql也会接受字符串中的换行符,但我已经在我的查询库中选择了该列,以便快速响应,我将使用别名now@user1264429:你应该接受解决你问题的答案。在这里查看如何感谢我将使用来自的别名的快速响应now@user1264429:你应该接受解决你问题的答案。在这里查看如何