$exquery="select * from tbl_expense where left(ex_date,4)='$ex_date_y'";
or
$exquery="select * from tbl_expense where ex_date like '$ex_date_y%'";

解决方案 »

  1.   

    怎么会不行?
    $exquery="select * from tbl_expense where left(ex_date,4)='$ex_date_y'";
    echo $exquery;
    mysql_query($exquery) or die (mysql_error());
    把SQL语句输出看看。不要你本身的$ex_date_y就是空的,或者没有ex_date这个字段。
    但是left(字段,参数)这样的写法肯定是对的!第二个的写法也绝对是对的。如果有错,也是你要么没表,要么没那个字段。
      

  2.   

    我重新试了.行了!
     substr(ex_date,0,4)='$ex_date_y'";
    为什么 我上面的这个不行呢!
      

  3.   

    因为MYSQL没有这个函数啊,你那个是PHP函数
      

  4.   

    MYSQL有substring这个函数。
    例如:
    substring('12345',2,3)=>"234"(跟PHP还是有点差别的)