table **salesrule_coupon**: fileds as the following:
coupon_id code
1 Registered_send_5
2 test
表:
salesrule_coupon_usage
文件如下: coupon_id customer_id times_used
1 1 1
1
... 14 ... 1..
现在,我想选择
times_used
where thecode =Registered_send_5
where customer_id=$id。如何编写sql命令?谢谢你。以下是我的,但不起作用。
$sql = "SELECT times_used FORM salesrule_coupon_usage as a
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=".'$id.";
当我把
SELECT times_used FORM salesrule_coupon_usage as a
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id=1
在phpmyadmin。它显示
您的SQL语法有错误;请查看对应于MySQL服务器版本的手册,在第1行的“salesrule_coupon_usage as a left join salesrule_coupon as b on a.co”附近使用正确的语法
最佳答案
有一个撇号(单引号)不应该在那里,你错拼了“from”:
$sql = "SELECT times_used FORM salesrule_coupon_usage as a
^
left join salesrule_coupon as b on a.coupon_id = b.coupon_id
where b.code = 'Registered_send_5' and customer_id= ".'$id;
^