我正在尝试选择与当月有相同月份的所有记录。
$date=date('Y-m-d');
$month=substr($date,5,2);
$res=mysql_query("SELECT DATE FROM reports");
while($row=mysql_fetch_assoc($res)){
$months=substr($row['DATE'],5,2);
}
我该怎么做?
答案 0 :(得分:3)
你可以让sql让你像这样处理
$query = "SELECT DATE FROM reports WHERE MONTH(DATE) = ".date("m");
如果你只想要那个月的所有内容今年,那么查询将如下所示:
$query = "SELECT DATE FROM reports WHERE YEAR(DATE) = ".date("Y")." MONTH(DATE) = ".date("m");
答案 1 :(得分:2)
为什么不
$query = 'SELECT DATE FROM reports WHERE MONTH(DATE) = MONTH(CURDATE())';