title: How to update MySQL column with thousands of data in PHP automatically using json data
body: <p>I have a "users" table with columns:</p>
  
  <pre><code>Id | user_id | name | ip_address | lat | lng | active
  </code></pre>
  
  <p>The latitude(lat) and longitude(lng) columns are empty, and I need to populate them with the approximate location (I do not need a precise location). Using this forum, in another question, I discovered that I would have to separate the IPs, and use a location library. Well. I created a function to extract the IP and added the IP2Location library to my project. It works if I take IP for IP, get latitude and longitude, and add one by one in MySQL, however, I have 125,000 records, and there is no way to do the job manually.
  Would anyone know how to do this?</p>
  
  <p>Using this function </p>
  
  <pre><code>function List_ip() {
      global $sqlConnect, $db;
      if ($db['loggedin'] == false) {
          return false;
      }
  
      $ips = mysqli_query($sqlConnect, "SELECT `user_id` , `ip_address` FROM " . T_USERS . " WHERE `active` = '1'");
      while ($fetched_data = mysqli_fetch_assoc($ips)) {
       $list_ip[] = array_map('utf8_encode', $fetched_data); 
      }    
  
     return $list_ip;
  
  }
  </code></pre>
  
  <p>I have the following json result</p>
  
  <pre><code>{
       "api_status": 200,
       "ips": [
           {
               "user_id": "1",
               "ip_address": "177.198.86.7x"
           },
           {
               "user_id": "21",
               "ip_address": "177.18.246.9x"
           },
           {
               "user_id": "52",
               "ip_address": "177.36.60.1x"
           }
       ]
  }
  </code></pre>
  
  <p>I have this script that can give me latitude and longitude based on IP</p>
  
  <pre><code>&lt;?php
  require_once './assets/libraries/vendor/ip2location/ip2location-php/IP2Location.php';
  
  $reader = new \IP2Location\Database('./IP2LOCATION-LITE-DB9.BIN', \IP2Location\Database::FILE_IO);
  
  $records = $reader-&gt;lookup('8.8.8.8', \IP2Location\Database::ALL);
  
  echo '&lt;pre&gt;';
  echo 'IP Number             : ' . $records['ipNumber'] . "\n";
  echo 'Latitude              : ' . $records['latitude'] . "\n";
  echo 'Longitude             : ' . $records['longitude'] . "\n";
  
  ?&gt;
  </code></pre>
  
  <p>How to insert latitude and longitude data for each of the IPs automatically?</p>
  
  <p>Sorry for the amount of code, I'm trying to be as clear as possible.</p>