我从表中得到这样的JSON输出。这里面的第一个数据是日期,第二个是11_OIC
[
[
984639600,
"23.49166667"
],
[
1521097200,
"22.985"
],
[
1552633200,
"22.34416667"
],
[
1584255600,
"19.98"
]
]
但我在找这样的东西。
{
"label": "OPE",
"data": [
[
984639600,
"23.49166667"
],
[
1521097200,
"22.985"
],
[
1552633200,
"22.34416667"
],
[
1584255600,
"19.98"
]
]
}
我使用的PHP代码如下:
private function productionhourlys(){
if($this->get_request_method() != "GET"){
$this->response('',406);
}
$query="SELECT distinct c.Date, c.11_OIC FROM productionhourlys c order by c.productionhourlyNumber desc";
$r = $this->mysqli->query($query) or die($this->mysqli->error.__LINE__);
if($r->num_rows > 0){
$result[] = array();
while($row = $r->fetch_row()) {
$row[0] = strtotime($row[0]);
$result[] = $row;
}
$this->response($this->json($result), 200); // send user details
}
$this->response('',204); // If no records "No Content" status
}
感谢您的帮助
还没有测试,请检查一下。
private function productionhourlys(){
if($this->get_request_method() != "GET"){
$this->response('',406);
}
$query="SELECT distinct c.Date, c.11_OIC FROM productionhourlys c order by c.productionhourlyNumber desc";
$r = $this->mysqli->query($query) or die($this->mysqli->error.__LINE__);
if($r->num_rows > 0){
$result[] = array();
while($row = $r->fetch_row()) {
$row[0] = strtotime($row[0]);
$result[] = $row;
}
$pass = array(
'label' => 'OPE',
'data' => $result
);
$this->response($this->json($pass), 200); // send user details
}
$this->response('',204); // If no records "No Content" status
}
这样尝试,
$result[] = array();
$result['label'] = "OPE";
while($row = $r->fetch_row()) {
$row[0] = strtotime($row[0]);
$result['data'] = $row;
}
while中$result变量的以下更改应该进行必要的更改,以获得所需的json格式。
private function productionhourlys(){
if($this->get_request_method() != "GET"){
$this->response('',406);
}
$query="SELECT distinct c.Date, c.11_OIC FROM productionhourlys c order by c.productionhourlyNumber desc";
$r = $this->mysqli->query($query) or die($this->mysqli->error.__LINE__);
if($r->num_rows > 0){
$result = array('label'=>'OPE');
$result['data'] = new array();
while($row = $r->fetch_row()) {
$row[0] = strtotime($row[0]);
$result[] = $row;
$result['data'][] = array(row[0],row[1]);
}
$this->response($this->json($result), 200); // send user details
}
$this->response('',204); // If no records "No Content" status
}