我的数据库(mysql)中有数据,我试图将其拉到 json 格式的页面,以便我可以选择数据以供将来参考。
当前数据输出
{
"quotes": [
{
"season": "3",
"episode": "2",
"lines": [
"Boys:\tSchool day, school day, teacher's golden ru\nKyle:\tAh, damn it! My little brother's trying to follow me to school, again. "
]
},
{
"season": "1",
"episode": "2",
"lines": [
"Episode 2 "
]
}
]
}
我正在努力的部分是lines
这样显示
"lines": [
{"Boys": "School day, school day, teacher's golden ru"},
{"Kyle": "Ah, damn it! My little brother's trying to follow me to school, again."}
]
我拥有的 PHP
$result = $con->query("SELECT * FROM quotes");
$response = array();
$i=0;
while ($row = $result->fetch_assoc()) {
$response[$i]['season']= $row['season'];
$response[$i]['episode']= $row['episode'];
$response[$i]['lines'] = explode('\n', $row['lines']);
$data['quotes'][$i] = $response[$i];
$i=$i+1;
}
$json_string = json_encode($data);
echo $json_string;
如果有人可以提供帮助,那就太好了!