所以我有这个PHP代码:
$des = 'Caticlan, Aklan';
require_once('dbConnect.php');
$sql = "SELECT * FROM appDB WHERE route='".$des."%'";
$r = mysqli_query($con,$sql) or die(mysqli_error($con));
$result = array();
//$row = mysqli_fetch_array($r);
while($row = mysqli_fetch_array($r)){
array_push($result,array(
"id"=>$row['id'],
"route"=>$row['route'],
"busName"=>$row['busName'],
"busType"=>$row['busType'],
"assignedTerminal"=>$row['assignedTerminal'],
"timeFirstTrip"=>$row['timeFirstTrip'],
"timeLastTrip"=>$row['timeLastTrip'],
"timeInterval"=>$row['timeInterval'],
"estFare"=>$row['estFare'],
"estDistance"=>$row['estDistance'],
"estTravelTime"=>$row['estTravelTime'],
"DualRoute"=>$row['DualRoute']
)); }
echo json_encode(array('busDetails'=>$result));
mysqli_close($con);
它应该返回来自db的数据,该数据与查询中的$des
匹配(并且以JSON
格式)。我试图运行这个,但它只显示了这个结果:
{"busDetails":[]}
但我希望它能像这样回归:
{
"busDetails": [{
"id": "8",
"route": "Caticlan, Aklan",
"busName": "Ceres Liner",
"busType": "regular",
"assignedTerminal": "Molo Terminal",
"timeFirstTrip": "03:30:00",
"timeLastTrip": "20:15:00",
"timeInterval": "20",
"estFare": "0",
"estDistance": "270",
"estTravelTime": "4hrs 27min",
"DualRoute": "San Jose, Pandan, Libetad"
}, {
"id": "17",
"route": "Caticlan, Aklan",
"busName": "Ceres Liner",
"busType": "regular",
"assignedTerminal": "Ceres Terminal",
"timeFirstTrip": "02:30:00",
"timeLastTrip": "17:00:00",
"timeInterval": "30",
"estFare": "0",
"estDistance": "226",
"estTravelTime": "4hr 33min",
"DualRoute": "Kalibo, Passi City"
}, {
"id": "18",
"route": "Caticlan, Aklan",
"busName": "Ceres Liner",
"busType": "aircon",
"assignedTerminal": "Ceres Terminal",
"timeFirstTrip": "03:00:00",
"timeLastTrip": "17:00:00",
"timeInterval": "30",
"estFare": "370",
"estDistance": "226",
"estTravelTime": "4hr 33min",
"DualRoute": "Kalibo, Passi City"
}]
}
没有显示错误。而且我也没有看到语法中的任何错误。