【发布时间】:2018-04-24 19:44:42
【问题描述】:
按城市和酒店搜索我的数据库中有哪些城市和酒店。我的代码不起作用。你能检查我的代码。可能是代码中的一些错误。
$countryName = $_GET['countrycode'];
$url = 'https://api.sandbox.amadeus.com/v1.2/hotels/search-box?apikey=EbdwHszYlp0f7fQB6YHo40SIhu4ZAomm&south_west_corner=51.328476%2C%20-10.758522&north_east_corner=55.320949%2C%20-5.474099&check_in=2017-06-19&check_out=2017-06-29&number_of_results=1000';
$response = file_get_contents($url);
$apiResults = json_decode($response, true);
$apiResults = $apiResults["results"];
$finalArray = [];
$dbResults = $wpdb->get_results(
$wpdb->prepare("
SELECT *
FROM hotels
WHERE county = %s",
$countryName
),
ARRAY_A
);
# If atleast 1 row is fecthed from
# database
if ($dbResults->num_rows) {
foreach ($dbResults as $dbResult) {
echo $storedCountryName = $dbResult["county"];
echo $storedHotelName = $dbResult["hotel"];
foreach ($apiResults as $apiResult) {
if ($storedCountryName === $apiResult['address']['city']
&& $storedHotelName === $apiResult['property_name'])
{
$finalArray[] = $apiResult;
}
}
}
}
var_dump($finalArray);
var_dump($finalArray);结果:
array (size=0)
empty
【问题讨论】:
-
SELECT * FROM hotels WHERE county = %s的结果是什么? -
嗨@vel,它的长代码。你能从这里下载吗expirebox.com/download/41c2c494246efa0ef25d15fafef95bbb.html