4
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_usedwhere code =Registered_send_5customer_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”附近使用正确的语法

4

3 回答 3

5

为什么你有'in from 的$id

它应该是FROM而不是FORM

于 2012-09-17T09:19:56.080 回答
4

那里有一个不应该出现的撇号(单引号),而您拼错了“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;
                                                           ^
于 2012-09-17T09:18:20.760 回答
4

最后您的查询中有错误:

$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;
                                                          ^
于 2012-09-17T09:18:23.563 回答