title: Loop to update MySQL Table
body: <p>I have an empty column and I would like to update rows with value of PHP function</p>
  
  <pre><code>&lt;?php
  function dystans1($lat1, $lon1, $lat2, $lon2) {
  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $km = $dist * 60 * 1.1515*1.609344;
  $unit = strtoupper($unit);
  return $km;      
  }
  
  $connection = @mysql_connect('localhost', '***', '***')
  
  or die('Brak połączenia z serwerem MySQL.&lt;br /&gt;Błąd: '.mysql_error());
  
  $db = @mysql_select_db('****', $connection)
  
  or die('Nie mogę połączyć się z bazą danych&lt;br /&gt;Błąd: '.mysql_error()); 
  
  
  
  
  $wynik = mysql_query("SELECT * FROM field_data_field_adres")
  or die('Błąd zapytania');
  
  if(mysql_num_rows($wynik) &gt; 0) {
  while($r = mysql_fetch_assoc($wynik)) {
  
      $km = dystans1($r['field_adres_lat'], $r['field_adres_lng'], 52.40633, 16.91811);
      echo $km;
      mysql_query("UPDATE field_data_field_adres SET dystans = $km ");
  
  
  
  }
  }
  
  ?&gt; 
  </code></pre>
  
  <p>Script inserts into dystans the same value. I would like to do that every row has another value</p>