Skip to content

Instantly share code, notes, and snippets.

@mamchenkov
Last active December 19, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamchenkov/5955343 to your computer and use it in GitHub Desktop.
Save mamchenkov/5955343 to your computer and use it in GitHub Desktop.
Quick and easy way to have multiple configurations for things like charts.
<?php
$charts = array(
'live1-ajax-total-count' => array(
'type' => 'line',
'title' => 'LIVE1 Total Count (ajax)',
'sql' => 'select .... ',
'callback' => 'minute_counts',
),
'live2-ajax-total-count' => array(
'type' => 'line',
'title' => 'LIVE2 Total Count (ajax)',
'sql' => 'select .... ',
'callback' => 'minute_counts',
),
);
function get_chart($chart_id) {
if (!empty($charts[$chart_id])) {
$data = mysql_query($charts[$chart_id]['sql']);
$data = call_user_func($charts[$chart_id]['callback'], $data);
return $data;
}
}
function get_charts() {
return array_keys($charts);
}
function minute_counts($data) {
// Data expectation:
// array('minute' => count);
// return json array
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment