字段列表中的“名称”列不明确


Column 'name' in field list is ambiguous

 <?php 
$cid=$_REQUEST['cn'];
 $sid=$_REQUEST['sn'];
 $query="select name,NAME from products a,category b where a.category_id=$cid and a.store_id=$cid and a.category_id=b.ID ";
 $result=  mysqli_query($link, $query)or die(mysqli_error($link));
?> 

我编写了简单的程序,它显示以下错误。 如果我提到名称 products.name 那么它会显示未知的列 products.name。

主要错误是字段列表中的列"名称"不明确

您需要

在所选列前面加上前缀,因为您要对包含相同名称列的多个表执行查询,例如:

select a.name as prod_name,b.NAME as cat_name 
from products a,category b 
  where a.category_id=$cid 
  and a.store_id=$cid 
  and a.category_id=b.ID