Failing to insert function call - where/how can I do it.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jh8025
Forum Newbie
Posts: 4
Joined: Tue Oct 21, 2008 11:04 am

Failing to insert function call - where/how can I do it.

Post by jh8025 »

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.

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);
?>
 
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Failing to insert function call - where/how can I do it.

Post by andyhoneycutt »

I would like to see the exact error you are getting, but from what I see I think you have an illegal assignment of your statement

Code: Select all

$data['system_os_name'] = determine_os($data['system_os_name']);
This doesn't look right to me because you are trying to assign a value to something of which you are trying to determine the value.

-Andy
Post Reply