$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%'";
or
$exquery="select * from tbl_expense where ex_date like '$ex_date_y%'";
$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(字段,参数)这样的写法肯定是对的!第二个的写法也绝对是对的。如果有错,也是你要么没表,要么没那个字段。
substr(ex_date,0,4)='$ex_date_y'";
为什么 我上面的这个不行呢!
例如:
substring('12345',2,3)=>"234"(跟PHP还是有点差别的)