title: Update mysql data via json
body: <p>Hey all So I am able to update the records from a json url and put it into Mysql now I am trying to update the records and it only grabs 1 value and updates all the records to the new value so its updating the existing records with only 1 record here is what I am using</p>
  
  <pre><code>$ApiLink     = "JSON URL HERE";
  $json_decode = (json_decode(file_get_contents($ApiLink), true));
  $output      = $json_decode["character_list"];
  
  /************************************************/
  
  $do_stuff = $dbh-&gt;prepare("UPDATE damage_given_vehicle SET veh_id=:veh_id, veh_name=:veh_name, veh_total=:total_value, veh_faction_nc=:veh_faction_nc, veh_faction_tr=:veh_faction_tr, veh_faction_vs=:veh_faction_vs WHERE character_number = :char_id");
  
  foreach ($output as $key =&gt; $value) {
      $character_id[$key] = $output[$key]["id"];
  
      if (isset($output[$key]["stats"]["vehicle_kills"]["vehicle"])) {
          $vehicle_kills[$key] = $output[$key]["stats"]["vehicle_kills"]["vehicle"];
          foreach ($vehicle_kills[$key] as $row) {
              $do_stuff-&gt;bindValue(':char_id', $update_id);
              $do_stuff-&gt;bindValue(':veh_id', $row["id"]);
              $do_stuff-&gt;bindValue(':veh_name', $row["name"]);
              $do_stuff-&gt;bindValue(':total_value', $row["value"]);
              $do_stuff-&gt;bindValue(':veh_faction_nc', $row["faction"]["nc"]);
              $do_stuff-&gt;bindValue(':veh_faction_tr', $row["faction"]["tr"]);
              $do_stuff-&gt;bindValue(':veh_faction_vs', $row["faction"]["vs"]);
              $do_stuff-&gt;execute();
          }
      }
  }
  </code></pre>
  
  <p>the database looks like this at first:</p>
  
  <pre><code>key | id | name | value 1 | value 2 | value 3 | value 4 |
  5428029729515051201     11  name_1 6 45 23 34 
  5428029729515051201     11  name_2 2 34     63 63
  5428029729515051201     11  name_3 34 0     17  17
  </code></pre>
  
  <p>after I use the update script it turns those values into:</p>
  
  <pre><code>5428029729515051201     11  name    34  0   17  17
  5428029729515051201     11  name    34  0   17  17
  5428029729515051201     11  name    34  0   17  17
  </code></pre>
  
  <p>if you are curious how the script enters the json data here you go:</p>
  
  <pre><code>$stmt = $dbh-&gt;prepare("
      INSERT INTO damage_given_vehicle (
          character_number, veh_id, veh_name, veh_total,
          veh_faction_nc, veh_faction_tr, veh_faction_vs)
      VALUES(
          :char_id, :veh_id, :veh_name, :total_value,
          :veh_faction_nc, :veh_faction_tr, :veh_faction_vs)
  ");
  foreach ($output as $key =&gt; $value) {
      $character_id[$key] = $output[$key]["id"];
  
      if (isset($output[$key]["stats"]["vehicle_kills"]["vehicle"])) {
          $vehicle_kills[$key] = $output[$key]["stats"]["vehicle_kills"]["vehicle"];
          foreach ($vehicle_kills[$key] as $row) {
              $stmt-&gt;bindValue(':char_id', $character_id[$key]);
              $stmt-&gt;bindValue(':veh_id', $row["id"]);
              $stmt-&gt;bindValue(':veh_name', $row["name"]);
              $stmt-&gt;bindValue(':total_value', $row["value"]);
              $stmt-&gt;bindValue(':veh_faction_nc', $row["faction"]["nc"]);
              $stmt-&gt;bindValue(':veh_faction_tr', $row["faction"]["tr"]);
              $stmt-&gt;bindValue(':veh_faction_vs', $row["faction"]["vs"]);
              $stmt-&gt;execute();
          }
      }
  } 
  </code></pre>
  
  <p>How do I get it to update every array seperately, If I do a var_dump on any of the $row[""] they produce the array how it should be displayed but when it goes through and enters into mysql it only grabs 1 value </p>
  
  <p>THANKS!</p>