简体   繁体   English

运行代码时出现以下错误

[英]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.

相关问题 连接到我的数据库时出现以下错误 - I am getting following error while connecting to my database 不能让它在我的代码上工作我不知道为什么,我收到以下错误:下面 - cant get this to work on my code i dont know why, I am getting the following error: below 我的.htaccess文件出现以下错误 - I am getting the following error with my .htaccess file 为什么在尝试使用图形 API 发送电子邮件时出现以下不受支持的媒体错误? - Why I am getting the following unsupported media error while trying to send the email using graph api? 我试图在PHP中使用亚马逊api代码,但它给了我错误的不支持版本以下是我的代码 - I am trying to use amazon api code in php but it is giving me error of not supported version following is my code 为什么我的代码出现PHP致命错误? - Why am I getting a PHP Fatal error with my code? 我无法获得以下PHP代码的期望输出 - I am not getting the desired output for the following PHP code 运行代码时在网站上出现500错误 - Getting 500 error on the website while running the code jQuery JSON - 为什么我收到以下错误? - jQuery JSON - why am I getting the following error? 在运行PHP bin / magento deploy:mode:set production时,我在magento 2.1上遇到错误 - While running PHP bin/magento deploy:mode:set production I am getting error on magento 2.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM