Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i use a foreach on a foreach php
    primarykey
    data
    text
    <p>hi guys i have this script but obviously im not using foreach right i was wondering is there anyway i could combine these two requests to works as one </p> <pre><code>$url = "http://api.website.com/1.0/country?source=ballsche&amp;programid=5380&amp;campaignid=100000"; $ch = curl_init(); $timeout = 0; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $rawdata = curl_exec($ch); curl_close($ch); $array = json_decode($rawdata,true); foreach($array as $obj) { $country = $obj['country']; $countrycode = $obj['countryCode']; } foreach($countrycode as $did) { $wgurl = "http://api.website.com/1.0/city?source=ballsche&amp;programid=5380&amp;campaignid=100000&amp;country-code=$did"; $wgch = curl_init(); $wgtimeout = 0; curl_setopt($wgch, CURLOPT_URL, $wgurl); curl_setopt($wgch, CURLOPT_HEADER, 0); curl_setopt($wgch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($wgch, CURLOPT_CONNECTTIMEOUT, $wgtimeout); $wgrawdata = curl_exec($wgch); curl_close($wgch); $wgarray = json_decode($wgrawdata,true); } foreach($wgarray as $wgobj) { $city = $wgobj['city']; $citycode = $wgobj['cityCode']; if($city){ $sql = "INSERT INTO `pt_city` (city, citycode) VALUES ('$city', '$citycode')"; database_queryModify($sql,$result); }else{ echo "dint work"; } } </code></pre> <p>there must be an easy way to do this im guesing creating another array from the data but i cant quite get it right i keep getting errors ive tried this and a few other things my problem is i need to cycle trough county codes and make requests from the code there a 150 requests i need to cycle trough to get all the city information and for each request i need to decode the json thats coming back and insert it into my city table</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload