0

我有以下代码计算每月发送的消息数量。可以改成每天吗?我尝试了许多更改,但都没有成功。有什么建议么?非常感谢您!我对 PHP/MySQL 还很陌生。另外,我知道当前的 MySQL 查询已被弃用!:

$vmYear = date("Y"); 
$vmMonth = date("m"); 

$vmfromdate = mktime(0,0,0,$vmMonth,"1",$vmYear); 
$vmtodate = mktime(0,0,0,$vmMonth,"31",$vmYear); 

$verifmessagespermonth = mysql_query("SELECT ID FROM messages WHERE msg_from = '$session_memberid' AND ( time BETWEEN '$vmfromdate' AND '$vmtodate' )"); 
$nummessagesthismonth = mysql_num_rows($verifmessagespermonth); 
} else { 
$nummessagesthismonth = 0; 
} 
4

2 回答 2

2

通过添加日期(假设您仅存储日期),将 int 保持在与您相同的结构中。如果您存储日期+时间,则可能需要将0,0,0from更改$vmtodate23,59,59

$vmYear = date("Y"); 
$vmMonth = date("m");
$vmDay = date("d");

$vmfromdate = mktime(0,0,0,$vmMonth,$vmDay,$vmYear); 
$vmtodate = mktime(0,0,0,$vmMonth,$vmDay,$vmYear);

如果您愿意,这仍然允许您制作其他范围

于 2013-06-12T10:01:13.913 回答
0

如果我正确理解了您可以使用此查询的要求:

SELECT 
  ID 
FROM 
  messages 
WHERE 
  msg_from = '$session_memberid' 
  AND time BETWEEN 
     DATE_FORMAT(NOW() , '%Y-%m-%d 00:00:00' ) 
     AND DATE_FORMAT(NOW() , '%Y-%m-%d 23:59:59' ) 
于 2013-06-12T09:58:54.683 回答