【发布时间】:2015-05-29 06:52:35
【问题描述】:
我正在使用 ms 访问 odbc 获取 sql 数据。但是我没有得到我想要的格式的结果。这是我的代码:
$rs = odbc_exec($con, $sql);
if (!$rs) {
exit("There is an error in the SQL!");
}
$data[0] = array('D','CPU_Purchased_ghz');
$i = 1;
while($row = odbc_fetch_array($rs)) {
$data[$i] = $row;
$i++;
}
odbc_close($con); // Closes the connection
$json = json_encode($data); // Generates the JSON, saves it in a variable
echo $json;
我得到结果的方式是:
[
["D","CPU_Purchased_ghz"],
{"D":"2015-03-14 00:00:00","CPU_Purchased_ghz":"10.00"},
{"D":"2015-03-15 00:00:00","CPU_Purchased_ghz":"10.00"},
{"D":"2015-03-16 00:00:00","CPU_Purchased_ghz":"10.00"}
];
我希望它看起来像这样:
[
["D","CPU_Purchased_ghz"],
[""2015-03-14 00:00:00",10.00],
["2015-03-16 00:00:00",10.00]
]
知道如何解决/更改我的代码吗?
【问题讨论】: