Page 1 of 1

What is wrong with this code?

Posted: Fri Nov 20, 2009 7:19 am
by klevis miho
Can anyone tell me what is wrong with this code:

Code: Select all

$sql = "SELECT title, latitude, longitude FROM jos_phocamaps_marker";
$query = mysql_query($sql) or die(mysql_error());
 
$sqlInsert = 'UPDATE jos_js_job_countries SET latitude = "$latitude", longitude = "$longitude" WHERE name = "$countryName"';
 
while($row = mysql_fetch_array($query)) {
$latitude = $row['latitude'];
$longitude = $row['longitude'];
$countryName = $row['title'];
 
mysql_query($sqlInsert);
}
What I wan't is probably clear here: When I do a "SELECT title, latitude, longitude FROM jos_phocamaps_marker" it displays me:
title latitude longitude
Germany 51.165691 10.451526
Austria 47.516231 14.550072

I want to get those coordinates and to add them into another table called jos_js_job_countries.


I would appreciate any help

Re: What is wrong with this code?

Posted: Fri Nov 20, 2009 7:53 am
by jayshields
Put yout SQL query variable inside the loop, just above where you execute it, then see what happens.

Re: What is wrong with this code?

Posted: Fri Nov 20, 2009 7:57 am
by klevis miho
I did it already:

Code: Select all

$sql = "SELECT title, latitude, longitude FROM jos_phocamaps_marker";
$query = mysql_query($sql) or die(mysql_error());
 
while($row = mysql_fetch_array($query)) {
$latitude = $row['latitude'];
$longitude = $row['longitude'];
$countryName = $row['title'];
 
$sqlInsert = 'UPDATE jos_js_job_countries SET latitude = "$latitude", longitude = "$longitude" WHERE name = "$countryName"';
mysql_query($sqlInsert) or die(mysql_error())
}

Re: What is wrong with this code?

Posted: Fri Nov 20, 2009 8:08 am
by klevis miho
jos_phocamaps_marker table
title varchar(250)
latitude varchar(20)
longitude varchar(20)

jos_js_job_countries table
name varchar(100)
latitude varchar(20)
longitude varchar(20)


The jos_js_job_countries has a 50 records of just names, latitude and longitude are empty

Re: What is wrong with this code?

Posted: Fri Nov 20, 2009 8:44 am
by jayshields
Variables inside single quotes are not evaluated.

Change this line:

Code: Select all

$sqlInsert = 'UPDATE jos_js_job_countries SET latitude = "$latitude", longitude = "$longitude" WHERE name = "$countryName"';
to

Code: Select all

$sqlInsert = "UPDATE jos_js_job_countries SET latitude = '$latitude', longitude = '$longitude' WHERE name = '$countryName'";

Re: What is wrong with this code?

Posted: Fri Nov 20, 2009 8:58 am
by klevis miho
jayshields it worked :D, thank you very much.
I thought I did try this out lol, my thought was wrong :)
Thnx very much