Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:55:59+00:00 2026-06-09T18:55:59+00:00

hi guys i have this script but obviously im not using foreach right i

  • 0

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

$url = "http://api.website.com/1.0/country?source=ballsche&programid=5380&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&programid=5380&campaignid=100000&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";
    }

}

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:56:00+00:00Added an answer on June 9, 2026 at 6:56 pm

    just put foreach inside each other like this

    $url = "http://api.website.com/1.0/country?source=ballsche&programid=5380&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&programid=5380&campaignid=100000&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";
                }
            }
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have this sign up script and I'm using mysql_real_escape_string .I know
Hello Guys! I started learning python GUI development. Let's say I have this script:
hey guys having this really simple problem but cant seem to figure out have
I'm using the init.d script from this: http://wiki.nginx.org/RedHatNginxInitScript but this script sucks on my
Hello Guys! Let's say I have some page which I got with this script:
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
hey guys i have got this far with a chat system but now i
I'm not new to web dev but I was just wondering if you guys
Hi guys I have this script here, which counts the characters and lines, now
Hi guys i have this line of code in a perl script where i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.