What is wrong with this code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

What is wrong with this code?

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: What is wrong with this code?

Post by jayshields »

Put yout SQL query variable inside the loop, just above where you execute it, then see what happens.
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: What is wrong with this code?

Post 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())
}
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: What is wrong with this code?

Post 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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: What is wrong with this code?

Post 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'";
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: What is wrong with this code?

Post 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
Post Reply