我已经检查过类似的答案。但我在这里有不同的问题!
要创建 googlce char,我通过从表中获取数据来创建 json 字符串。表只有两行。下面是 json 字符串的构造方式:
$result = $mysqli->query('SELECT * FROM view_name');
$p= $mysqli->query('SELECT Index_val FROM view_name where ind_type=pcount');
//echo "$p";
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'pcount', 'type' => 'string'),
array('label' => 'ncount', 'type' => 'number')
);
/* Extract the information from $result */
foreach($result as $r) {
$temp = array();
$temp[] = array('v' => (string) $r['ind_type']);
$temp[] = array('v' => (int) $r['Index_val']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
这里我只需要从数据库pcount
和ncount
. 我不想使用上述程序。
我想要的是手动从表中获取值pcount
,ncount
存储在变量中并构造 json 字符串。
像这样:
$p= $mysqli->query('SELECT Index_val FROM view_name where ind_type=pcount');
//如果错误,请更正 get get ncount
。
现在我怎样才能从这个创建上面的 json 字符串?结果字符串将如下所示:
{
"cols":[
{"label":"pcount","type":"string"},
{"label":"ncount","type":"number"}],
"rows":[
{"c":
[
{"v":"pcount"},
{"v":179} // 179 is pcount
]
},
{"c":
[
{"v":"ncount"},
{"v":285} //285 is ncount
]
}
]
}