Search by city & hotels which city and hotels have on my database. My code is not worked. Can you check my code. Maybe some mistake in the code.
$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); Result:
array (size=0)
empty