Trying to do math across columns for each row... not working
Posted: Thu Nov 03, 2011 3:53 am
I can't figure the answer to this.
I have a table called "zip_codes" with columns ZIP, STATE, LATITUDE, LONGITUDE, CITY, FULL_STATE, and POINT.
I'm trying to write a script to automatically take the latitude and longitude of each row, divide them, and put the result into column POINT(BIGINT type).
This is the code I currently have:
When I run the page, my POINT column becomes populated with the same exact number for each row. How could I do this math operation for each row without doing it manually? (there's 42000 rows!) Thanks
I have a table called "zip_codes" with columns ZIP, STATE, LATITUDE, LONGITUDE, CITY, FULL_STATE, and POINT.
I'm trying to write a script to automatically take the latitude and longitude of each row, divide them, and put the result into column POINT(BIGINT type).
This is the code I currently have:
Code: Select all
$result = mysql_query("SELECT * FROM zip_codes");
while ($row = mysql_fetch_array($result)) { //set variables for rows
$lat = $row['latitude'];
$lon = $row['longitude'];
}
$sql = "UPDATE zip_codes SET point = ($lat / $lon)";
$result = mysql_query($sql);