我将此代码编写为输出为google图表的json格式。但是,数字的返回值变为字符串,无法通过谷歌图表读取。
$rows = array();
foreach($data as $item) {
$a = new stdClass;
$a->v = $item->location_name;
$a->f = null;
$b = new stdClass;
$b->v = $item->count;
$b->f = null;
$c = new stdClass;
$c->c = array($a, $b);
$rows[] = $c;
}
$cols1 = new stdClass;
$cols1->id = '';
$cols1->label = 'STATE';
$cols1->pattern = '';
$cols1->type = "string";
$cols2 = new stdClass;
$cols2->id = '';
$cols2->label = 'TOTAL';
$cols2->pattern = '';
$cols2->type = "number";
$returndata = new stdClass;
$returndata->cols = array($cols1, $cols2);
$returndata->rows = $rows;
echo json_encode($returndata);
查询是这样的:
$sql = "Select ljl.location_id, count(ljj.job_id) as count, ljl.location_name from {local_jobs_job} ljj inner join {local_jobs_location} ljl on ljj.job_location = ljl.location_id group by ljl.location_name";
答案 0 :(得分:0)
您可以将已知的“字符串编号”列投射到$b->v = intval($item->count);
或(int) $item->count