<?php
include_once("connect.php");
$query = "
select date, sum(amount) as total
from expenses
where date <= NOW()
and date >= Date_add(Now(),interval - 7 day)
group by date;";
$dateArray = Array();
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["total"];
echo $row["date"];
array_push($dateArray,$row);
}}
echo $dateArray[0]["total"];
$dataPoints = array(
array("y" => 25, "label" => "Sunday"),
array("y" => 15, "label" => "Monday"),
array("y" => 25, "label" => "Tuesday"),
array("y" => 5, "label" => "Wednesday"),
array("y" => 10, "label" => "Thursday"),
array("y" => 0, "label" => "Friday"),
array("y" => 20, "label" => "Saturday")
);
?>
我試影像這樣運行它并得到一個錯誤,所以不確定我是否可以將每個陣列元素“y”設定為數量之一,并將“標簽”設定為這樣的唯一日期
$dataPoints = array(
foreach($dateArray as $item) {
array("y" => $dateArray("amount"), "label" => $dateArray("date"))
}
)
uj5u.com熱心網友回復:
嘗試如下:
$dataPoints = array();
foreach($dateArray as $item) {
array_push($dataPoint, array("y" => $dateArray("amount"), "label" => $dateArray("date")));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/479823.html
標籤:javascript php mysql 数组
