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.
However I created a list which should be used for every query (made a form to choose month and year).
My problem is that the code doesnt enter the loop to create the new values (Day and Count).
Any idea?
Here the code:
$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();
}
$daysis set to 0, it only changes if$monthsis 2,4,6,9,11 so for every other value of$month$dayswill be 0 and not enter the for loop.