我想按日期和域计算记录数。 php查询在phpmyadmin中工作得很好,但在 php代码中它返回null。我希望像今天,明天一样按日期显示。加入表格和按日期和域名计算。
wp_domain_prefix TABLE
wp_projectid_1表
PHP查询
<?php
$querys = "SELECT `wp_domain_prefix.domain`, count( `wp_projectid_1.record_id` )
FROM `wp_domain_prefix`, `wp_projectid_1` WHERE `wp_domain_prefix.domain` = `wp_projectid_1.domain` AND
`wp_projectid_1.datess` BETWEEN '2014-10-07' AND '2014-10-08'";
$record = mysql_query($querys);
echo $record[count('wp_projectid_1.record_id')];
?>
答案 0 :(得分:1)
将查询更改为,
$querys = "SELECT wp_domain_prefix.domain, count(wp_projectid_1.record_id) FROM wp_domain_prefix, wp_projectid_1 WHERE wp_domain_prefix.domain = wp_projectid_1.domain WHERE
wp_projectid_1.datess BETWEEN '2014-10-07' AND '2014-10-08'";
$record = mysql_query($querys);
$row = mysql_fetch_array($record);
echo $row['record_id'];
答案 1 :(得分:0)
您需要将GROUP BY用于聚合函数,例如COUNT()
$querys =
"SELECT wp_domain_prefix.domain, count( wp_projectid_1.record_id )
FROM wp_domain_prefix, wp_projectid_1
WHERE wp_domain_prefix.domain = wp_projectid_1.domain
AND wp_projectid_1.datess BETWEEN '2014-10-07' AND '2014-10-08'
GROUP BY wp_domain_prefix.domain";
$record = mysql_query($querys);
$row = mysql_fetch_row($record);
print_r($row);
答案 2 :(得分:0)
最好使用mysqli而不是mysql,因为不推荐使用mysql,支持很快就会结束。
在mysql_fetch_row
尝试这样的
mysql_query
获取数据
$querys = "SELECT `wp_domain_prefix.domain`, count( `wp_projectid_1.record_id` ) as totalcount FROM `wp_domain_prefix`, `wp_projectid_1` WHERE `wp_domain_prefix.domain` = `wp_projectid_1.domain` AND
`wp_projectid_1.datess` BETWEEN '2014-10-07' AND '2014-10-08'";
$record = mysql_query($querys);
$row = mysql_fetch_row($record);
print_r($row);
echo $row['totalcount'];