0
我試圖搜索過程輸入與PHP和發送到JSONPHP查詢多個陣列JSON
JSON的輸出是這樣的:
{
"err": 0,
"msg": "",
"data": {
"f": 0,
"hotel": [
{
"att": 25147,
"name": "Crowne Plaza Changi Airport",
"city": "Singapore",
"country": "Singapore"
}
],
"city": [
{
"att": "-2679652",
"name": "Singapore",
"region": "",
"country": "Singapore",
"nr_hotels": ""
}
]
}
}
我與測試序列嘗試,但不起作用
<?
$query = 'SELECT * FROM hotel WHERE (hotel_name LIKE "%'.$q.'%" OR city LIKE "%'.$q.'%")';
$result=mysql_query($query);
// Do Search
$json_array = array();
while ($search=mysql_fetch_array($result)){
$search_array = array(
"err"=>"","msg"=>"",
"hotel" => array(
"att" => $search['hotel_id'],
"name" => $search['hotel_name'],
"city" => $search['city'],
"country" => $search['country']),
"city"=> array(
"att"=> $search['hotel_id'],
"name" => $search['city'],
"country" => $search['country'])
);
array_push($json_array,$search_array);
}
echo json_encode($json_array);
?>
我這種變化,但只顯示1個記錄不是所有關鍵詞搜索類似
$query = 'SELECT * FROM hotel WHERE (hotel_name LIKE "%'.$q.'%" OR city LIKE "%'.$q.'%")';
$result=mysql_query($query);
// Do Search
$json_array = array();
while ($hasil=mysql_fetch_array($result)){
$search_array = array(
"err"=>intval("0"),"msg"=>"","data"=>array("f"=>intval("114"),
"hotel"=>array(
$hotel_array = array(
"att"=> $hasil['hotel_id'],
"name" => $hasil['hotel_name'],
"city" => $hasil['city'],
"country" => $hasil['country']
)),
"city"=>array(
$city_array = array(
"att"=> $hasil['hotel_id'],
"name" => $hasil['city'],
"city" => $hasil['city'],
))
));
}
echo json_encode($search_array);
?>
請幫助數組語法如何感謝
它類似的過程與本網站http://www.myhotelfinder.com/id/home/dohttp/predict?q=singapore
謝謝這個JSON輸出我的意思
<?
$query = 'SELECT * FROM hotel WHERE (hotel_name LIKE "%'.$q.'%" OR city LIKE "%'.$q.'%")';
$result=mysql_query($query);
// Do Search
$json_array = array(
"err" => "",
"msg" => "",
"data" => array(
"f" => 0,
"hotel" => array(),
"city" => array()
)
);
while ($hasil=mysql_fetch_array($result)){
$hotel = array(
"att" => $hasil['hotel_id'],
"name" => $hasil['hotel_name'],
"city" => $hasil['city'],
"country" => $hasil['country']
);
$city = array(
"att"=> $hasil['hotel_id'],
"name" => $hasil['city'],
"country" => $hasil['country']
);
array_push($json_array["data"]["hotel"], $hotel);
array_push($json_array["data"]["city"], $city);
}
echo json_encode($json_array);
?>
吻^^
這是什麼似乎是問題?每當你寫完'$ search_array'時,循環中的 – Ghost 2014-09-24 04:43:56
就沒有意義了。但是在這個問題上你沒有正確描述這個問題。 – mithunsatheesh 2014-09-24 04:49:32