I'm struggling with this problem since a couple of days and I can not find the right solution.
I would like to retrieve the data from this database table via PHP:
and, again with php, have a JSON output similar to this:
[{
"label": "2013-01-07",
"value": "4"
}, {
"label": "2013-01-06",
"value": "65"
}, {
"label": "2013-01-05",
"value": "96"
}]
I wrote a function that retrieves the info from the table but I'm not able to put them in the correct order and also there are probably better ways to do it..
function getUsersCountOnDate()
{
$result = mysql_query("Select FROM_UNIXTIME(regtime, '%Y-%m-%d') as date, count(FROM_UNIXTIME(regtime, '%Y-%m-%d')) as count from users group by FROM_UNIXTIME(regtime, '%Y-%m-%d') order by FROM_UNIXTIME(regtime, '%Y-%m-%d') DESC");
while($row = mysql_fetch_array($result)){
$date[] = $row['date'];
}
$result = mysql_query("Select FROM_UNIXTIME(regtime, '%Y-%m-%d') as date, count(FROM_UNIXTIME(regtime, '%Y-%m-%d')) as count from users group by FROM_UNIXTIME(regtime, '%Y-%m-%d') order by FROM_UNIXTIME(regtime, '%Y-%m-%d') DESC");
while($row = mysql_fetch_array($result)){
$count[] = $row['count'];
}
$merged = array_merge($date, $count);
return json_encode($merged);
}
What I retrieve is like this: ["2016-03-18","2016-03-13","2016-03-11","2016-03-06","2016-03-04","6","1","1","1","1"]
Can anyone help me please?
mysql_. They are obsolete, not maintained, have been removed from PHP 7+, and unsafe. Use the equivalentmysqli_functions or the modernPDOdatabase classes.