0

我试图显示created_at日期介于 2 个日期之间的行数。

这是我的代码:

$result=mysql_query("select * from payments 
                     where created_at between '2013/10/01 00:00:00' and '2013/10/30 00:00:00'") 
                     or die('You need to add an administrator ' );

$counter = mysql_query("select * from payments 
                        where created_at between '2013/10/01 00:00:00' and '2013/10/30 00:00:00'");

$row = mysql_fetch_array($result);

$id = $row['id'];

$num = mysql_fetch_array($counter);
$countjan = $num["id"];

然而,当我回声

<?php echo"$jan";?>

这显示0了我如何让它工作的任何想法

Ps 此日期范围内有 1 行

4

3 回答 3

0

你可以这样查询:

SELECT COUNT(*) FROM your_table WHERE created_at >= '2013/10/01 00:00:00' AND created_at <= '2013/10/30 00:00:00'

顺便说一句:您应该使用 MySQL 日期格式或时间戳。

于 2013-10-31T21:50:26.627 回答
0

尝试这个

$res=mysql_query("SELECT * FROM your_table WHERE created_at >= '2013/10/01 00:00:00' AND created_at <= '2013/10/30 00:00:00'");
if($res)
{
$count=mysql_num_rows($res);
echo $count;
}
于 2013-11-01T12:03:57.560 回答
0

SELECT COUNT(*) FROM your_table WHERE created_at >= '2013/10/01 00:00:00' AND created_at <= '2013/10/30 00:00:00'

于 2013-11-03T22:50:31.867 回答