Failing to insert function call - where/how can I do it.
Posted: Wed Nov 12, 2008 7:37 am
Ok so the below page makes an sql call and then sends the data to the yahoo yui datatable api to be processed. My question is where can I modify some of the sql query data before its passed to the api. For example the below query retrieves 'system_os_name'. I would like to format this output using 'determine_os' I have stored within one of the include pages.
I tried adding it in this way, in the while loop, but it errors out with bad syntax.
Here's the main code. Any help is much apreciated. All I need to do is have the ability to apply formatting functions to query data before I pass it to the JS api.
I tried adding it in this way, in the while loop, but it errors out with bad syntax.
Code: Select all
while ($data = mysql_fetch_assoc($result)) {
$data['system_os_name'] = determine_os($data['system_os_name']);
$json_data[] = $data;
}
Here's the main code. Any help is much apreciated. All I need to do is have the ability to apply formatting functions to query data before I pass it to the JS api.
Code: Select all
<?php
$datatable = array();
$config = array();
$datatable['div_name'] = 'test_get_os';
$div_title = 'Operating Systems';
$json_data = array();
include_once("includes/mysql.inc");
include_once("include_functions.php");
$query = "SELECT system_os_name as item_id, COUNT( system_uuid ) AS total,
round( 100/ (SELECT count(system_uuid) FROM system WHERE system_os_name != '') * COUNT( system_uuid ), 2 ) AS percentage
FROM system WHERE system_os_name != '' GROUP BY item_id ORDER BY total desc";
$result = db_mysql_query($query);
while ($data = mysql_fetch_assoc($result)) {
$json_data[] = $data;
}
$datatable['columns'] ='
{"key":"item_id","label":"Name","sortable":true,"formatter":YAHOO.nsstest.showLongString},
{"key":"total","label":"Total","sortable":true,"formatter":"number"},
{"key":"percentage","label":"%","sortable":true,"formatter":"number"}
';
$datatable['fields'] ='
{"key":"item_id","parser":YAHOO.util.DataSource.parseString},
{"key":"total","parser":YAHOO.util.DataSource.parseNumber},
{"key":"percentage","parser":YAHOO.util.DataSource.parseNumber}
';
$datatable['data'] = json_encode($json_data);
$config['paginator']['totalRecords'] = count($json_data);
$config['paginator']['rowsPerPage'] = 10;
$config['paginator']['template'] = 'short';
$config['datatable']['width'] = '210';
$datatable['config'] = $test_webui->generateJavaScriptDataTableConfig($config);
$test_webui->js_string .= $test_webui->generateJavaScriptDataTable($datatable);
$test_webui->showDivBox($datatable['div_name'], $div_title);
?>