gpt4 book ai didi

php - 使用 php json 编码选择 mysql

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:48 27 4
gpt4 key购买 nike

这里是我的代码:

$sql = "SELECT * FROM schedule_feednow WHERE IDMac = '".$_GET["IDMac"]."'";
$result = mysql_query($sql) or die(mysql_error());
$json_data = array();

while($rec = mysql_fetch_assoc($result)){
$Subjson = array();
$Subjson['IDMac'] = $rec['IDMac'];
$Subjson['DATETIME'] = $rec['DATETIME'];
$Subjson['Weight'] = $rec['Weight'];

array_push($json_data,$Subjson);


}

echo json_encode ($json_data);

和结果:

[{"IDMac":"C-01","DATETIME":"12:05:19 AM on June 23, 2017","Weight":"50"},{"IDMac":"C-01","DATETIME":"12:05:55 AM on June 23, 2017","Weight":"50"},{"IDMac":"C-01","DATETIME":"02:02:20 PM on June 23, 2017","Weight":"50"}]

但我不想要这个结果

我想要这个结果->

["Schedule":{"IDMac":"C-01","DATETIME":"12:05:19 AM on June 23, 2017","Weight":"50"},{"IDMac":"C-01","DATETIME":"12:05:55 AM on June 23, 2017","Weight":"50"},{"IDMac":"C-01","DATETIME":"02:02:20 PM on June 23, 2017","Weight":"50"}]

请帮我生成代码或训练我。非常感谢。

最佳答案

只需将您当前的结果放入一个带有键“Schedule”的数组中:

echo json_encode(array('Schedule' => $json_data));

关于php - 使用 php json 编码选择 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44722059/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com