我正在使用jqplot在图表中显示数据。我能够获取数组中的数据,但我遇到了一个小问题 绘制格式为
的数据[["Pens",10],["Pencils",30],["Erasers",40],["Charts",3]]
我以下列格式获取数据
[["Pens"],["10"],["Pencils"],["30"],["Erasers"],["40"],["Charts"],["3"]]
我的代码如下
PHP代码
$dbname = 'dbname';
$username = 'root';
$password = 'password1!';
try {
/* Establish the database connection */
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $conn->query("SELECT Compliancestatus,value FROM COUNT_VALUE WHERE Zone='PZ' and country='AU' and `Compliancestatus` is not null");
$jsonTable = json_encode($rows);
print_r($jsonTable);
} catch (PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
//mysql_close($conn);
$conn = null;
$rows = array();
foreach ($result as $r) {
$rows[] = array($r['Compliancestatus']);
// Values of each slice
$rows[] = array($r['value']);
}
请在这方面帮助我。
答案 0 :(得分:1)
更改此
$rows[] = array($r['Compliancestatus']);
// Values of each slice
$rows[] = array($r['value']);
要
$rows[] = array($r['Compliancestatus'],(int)$r['value']);