I am trying to use a fleet to build some data that is retrieved from MySQL db. I am logging user logs, and I have a SQL function that will track the number of visits per day for a given month, getStats ($ day). I read a few examples online on how to do this correctly, but for some reason, when I try to rob array data in my javascript file, it is "empty" → "data:". Below is my code. I use the CI framework, so if there are some questions about my code, this is most likely due to this. I have hardcoded data and it works great. Any help on this would be appreciated, as there is currently little to be done with databases.
Model ---> metrics.php
function showUsers() {
$num_days = cal_days_in_month(CAL_GREGORIAN, date(m), date(Y));
$first_day = strtotime(date('Y').'-'.date('m').'-01');
while( $i < $num_days ) {
$log = $this->db->getStats($first_day);
$first_day += 86400;
$flot_visits[] = '['.($first_day*1000).','.$log->fields['total'].']';
$i++;
}
$content['visits'] = '['.implode(',',$flot_visits).']';
$this->load->vars($content);
$this->load->view('metrics/user_metrics', $content);
}
View ---> user_metrics.php
<div id ="visits_graph" style="width:600px; height:300px"></div>
Javascript --- > user_metrics.js
function metrics() {
$.ajax({
type: "POST",
url: pathurl + "metrics/showUsers",
data: "",
success: function(data) {
graph_visits();
}
});
}
function graph_visits() {
$.plot($('#visits_graph'), [
{ label: 'Visits', data: <?php echo $visits ?> }
], {
xaxis: {
mode: "time",
timeformat: "%m/%d/%y"
},
lines: { show: true },
points: { show: true },
grid: { backgroundColor:
});
}