Home  >  Article  >  Backend Development  >  数据库查询问题

数据库查询问题

WBOY
WBOYOriginal
2016-06-23 14:26:10914browse

$asin=$_POST['key'];$sql="SELECT t.`item_code`,t.`package_area`,t.`asin`,t.`sku`,b.`pack_weight` ";$sql.="FROM `1_sku_comparison` t left join `1_product` b on t.`item_code`=b.`item_code` ";$sql.="WHERE t.`sku`='".$asin."' OR t.`asin`='".$asin."' OR t.`item_code`='".$asin."'";


现在的问题是当t.`item_code`=$asin这个条件满足时能查出数据,t.`sku`='".$asin."' OR t.`asin`='".$asin."'这两个条件满足时,就报没查到数据,但是我输出$sql后,用输出的$sql在phpmyadmin能查到数据。我是用ajax传值的,请问这是什么情况呢??


回复讨论(解决方案)

where t.`sku`='".$asin."'  and (t.`asin`='".$asin."' OR t.`item_code`='".$asin."')";

$sql.="WHERE t.`sku`='".$asin."' and (t.`asin`='".$asin."' OR t.`item_code`='".$asin."')";

t.`sku`='".$asin."' OR t.`asin`='".$asin."' OR t.`item_code`='".$asin."'";

我是要这个条件,问题是,现在执行结果是item_code可以查出来,asin和sku字段条件满足时查不出来

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn