0

I am used to working with querying data from database, this is my first time of using API, I got the API below from rapidapi.com, I want to use it to compare the cost of living is different states across the world. the major challenge I am having now is how to use sql SELECT statement with the API, what will be the table name if I want to use "SELECT * FROM tableName()" as usual. please anyone should help.

<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://cost-of-living-and-prices.p.rapidapi.com/cities",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "X-RapidAPI-Host: cost-of-living-and-prices.p.rapidapi.com",
        "X-RapidAPI-Key:"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    
    $result = json_decode($response, true);
    foreach((array)$result as $key=>$cities){
        foreach((array)$cities as $city){
            echo "<pre>";
            print_r($city['city_name']);
       
        }
    }
   
   
}

The sample of what I am trying to achieve with the API is in the link below https://www.budgetdirect.com.au/interactives/costofliving/compare/tokyo-vs-berlin/

I have already converted from json to Array

IDTech
  • 1
  • 1

0 Answers0