在我的项目中显示了有关图表的统计数据。
其中一项数据是本周和上周网站的点击次数。两者目前都在自己的折线图中。那里的所有内容也都显示没有任何问题。但现在我想把本周的数据和上周的数据放到一个折线图中,以便快速比较本周和上周网站的访问量。
因此,我尝试将两个查询的输出获取到一个 JSON 中,但总是收到此错误 ( json_encode() expects parameter 2 to be int, array given)。
我认为这应该以不同的方式解决,但我还没有找到任何其他想法或方法。
代码:
header("Content-Type: application/json");
include "../../../includes/db.php";
$stmt = $connection->prepare("SELECT website_stats_homepage AS current_week FROM website_stats WHERE yearweek(DATE(website_stats_date), 1) = yearweek(curdate(), 1) ORDER BY website_stats_date");
//$stmt = $connection->prepare("SELECT website_stats_homepage FROM website_stats WHERE website_stats_date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND website_stats_date < curdate() - INTERVAL DAYOFWEEK(curdate())-2 DAY");
$stmt->execute();
$result = $stmt->get_result();
$stmt1 = $connection->prepare("SELECT website_stats_homepage AS last_week FROM website_stats WHERE website_stats_date >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND website_stats_date < curdate() - INTERVAL DAYOFWEEK(curdate())-2 DAY");
$stmt1->execute();
$result1 = $stmt1->get_result();
$data = array();
foreach($result as $row) {
$data[] = $row;
}
$data1 = array();
foreach($result1 as $row1) {
$data1[] = $row1;
}
$stmt->close();
$stmt1->close();
echo json_encode($data, $data1);
撒科打诨