I try to make a diagram with RGraph(JS). I have a user counter on my site. And now I want to make a user-statistic with this diagram.
然而,我编制了一个清单,用于每一点(形成一个选择月和年的形式)。
我的问题是,《法典》将创造新的价值观(日子和大夫)的 lo。
任何想法?
该守则:
$days = 0;
$day_value = array();
//check months which have 30 days
if (in_array($month, array(4,6,9,11))) {
$days = 30;
}
//leapyear?
if ($month == 2) {
if ($year%4 == 0) {
$days = 29;
} else {
$days = 28;
}
}
//Count users for each day
for ($i=1; $i<=$days; $i++) {
$sql = "SELECT
Anzahl
FROM
Counter
WHERE
YEAR(Datum) = ".$year." AND
MONTH(Datum) = ".$month." AND
DAYOFMONTH(Datum) = ".$i." ";
if (!$result = $db->query($sql)) {
return $db->error;
}
$row = $result->fetch_assoc();
$day_value[$i] = (int)$row[ Anzahl ];
}
//delete list for new month/year
$sql = "DELETE
FROM
Statistics
";
if (!$result = $db->query($sql)) {
return $db->error;
}
//Create list with values for each day
for ($j=1; $j<=$days; $j++) {
$sql = "INSERT INTO
Statistics(Day,Count)
VALUES
(?, ?)";
$stmt = $db->prepare($sql);
if (!$stmt) {
return $db->error;
}
$stmt->bind_param( ii , $j, $day_value[$j]);
if (!$stmt->execute()) {
return $stmt->error;
}
$stmt->close();
}