Page 1 of 1
help with code
Posted: Mon Nov 20, 2006 9:20 pm
by garry27
can anyone tell me why i get the following errors:
missing ; before statement
map_data2.php?pos... (line 1)
var lat='54.517927442248'; var lng='-1.532475523414';Invalid query: Unknown column 'Amenities.postcode' in 'where clause'
lat is not defined
with the following code:
Code: Select all
//assign lan and lng values to jscript vars and output them to browser//
$jscript = 'var lat=' . $_GET['lat'] .'; var lng=' . $_GET['lng'] .';';
print $jscript;
error_reporting(E_ALL);// ^ E_NOTICE);
$chkbox_arr = array();
foreach($_GET as $key=>$value) {
if ($value !== '' && $key !=='lat' && $key !=='lng'){
$chkbox_arr[]=' AND Amenities.'.$key."='y'";
}
}
the code resides in map_data2.php and is called in create_crawl.php as so:
Code: Select all
echo xhtmlheader('Create Pub Crawl', 'KEY', 'map_data2.php?' . $_SERVER['QUERY_STRING'], 'mapFunctions.js');
where each param appears in <script> in the header.
i've echoed both $lan and $lng to the browser in create_crawl.php and they show up alright but somehow when i try and echo it in the mapdata script, it interferes with the current code. i tried to get arround this by eliminating the lan and lng vars in the foreach loop but it doesn't seem to have worked.
Posted: Mon Nov 20, 2006 9:26 pm
by feyd
garry27, seriously, think up more descriptive thread titles.
Where is this error showing up? Is it in your Javascript console? Is it in the page?
It looks like the error in the "invalid query" stuff. Which would tell me that your query needs the fixing, not your Javascript.
Posted: Mon Nov 20, 2006 9:48 pm
by garry27
ye i know.
i caught it in my firebug console. example:
http://www.nl-webspace.co.uk/~unn_p9218 ... =Find+Pubs
Posted: Mon Nov 20, 2006 10:05 pm
by garry27
also, it may hae something to do with the way i 'get' the coords to begin with. i'm using an external geocoder api which i send the coordinates to and it converts them to latitude and longitude and sends them back in php form.
you can see a better example on the query page itself:
http://www.nl-webspace.co.uk/~unn_p9218 ... ndpubs.php?
the problem i have with this page which i'm just noticing is that the query to the website is a bit too slow for the code that i have. how do i stop my php executing while it waits for a server response:
findpubs.php
Code: Select all
$postcode = urlencode( $_GET['postcode'] );
if (isset($postcode)) {
$api_key = 'xxxxxxxxxxxxxxxxxx';
$url = 'http://www.nearby.org.uk/api/convert.php?key=' . $api_key . '&p=' . $postcode . '&output=php';
include $url;
$lat = $convert_output['ll-wgs84']['lat'];
$lng = $convert_output['ll-wgs84']['long'];
//print "lat = ".$convert_output['ll-wgs84']['lat']."<br/>";
//print "long = ".$convert_output['ll-wgs84']['long']."<br/>";
if ( isset($lat) && isset ($lng) ) {
$formaction = 'create_crawl.php';
}
else{
$formaction = 'findpubs.php';
echo 'the postode you entered did not return any results. please try again';
}
}
else {
$formaction = 'findpubs.php';
}
ta for your help mate. i'll check back in the morning cos its way pas my bedtime.
garry
Posted: Mon Nov 20, 2006 10:11 pm
by feyd
The error is entirely about your query, nothing more at this point. Post your query creation code. All of it.
Posted: Tue Nov 21, 2006 10:43 am
by garry27
here's the entire script for map_data2.php with the query included:
Code: Select all
<?php
require_once('common.php');
db_connect();
//assign lan and lng values to jscript vars and output them to browser//
$jscript = 'var lat=' . $_GET['lat'] .'; var lng=' . $_GET['lng'] .';';
print $jscript;
error_reporting(E_ALL);// ^ E_NOTICE);
$chkbox_arr = array();
foreach($_GET as $key=>$value) {
if ($value !== '' || $key !=='lat' || $key !=='lng'){
$chkbox_arr[]=' AND Amenities.'.$key."='y'";
}
}
//string together all elements in a single string
$sql_str = implode(" ", $chkbox_arr );
//$sql = mysql_query ("select Pubs.pubID from Pubs, Amenities where Pubs.pubID=Amenities.pubID $filter") or die( 'Invalid query: ' . mysql_error() );
$sql = mysql_query ("select Pubs.Latitude, Pubs.Longitude, Pubs.pubName, Pubs.pubStreetNo,
Pubs.pubStreet, Pubs.pubCity, Pubs.pubCounty, Pubs.pubPostcode,
Pubs.pubPhone from Pubs, Amenities WHERE Pubs.pubID=Amenities.pubID $sql_str")
or die( 'Invalid query: ' . mysql_error() );
while( $elements = mysql_fetch_array($sql) ) {
$br = '<br>';
$markers[] = '{'
." 'latitude' : " .$elements[0] .','
." 'longitude' : " .$elements[1] .','
." 'tooltip' : '" .$elements[2]."'"
// ."'address': '" .$elements[3] .$br .$elements[4] .$br .$elements[5]
// .$br .$elements[6] .$br .$elements[7] ."',"
// ."'phone': '" .$elements[8] ."'"
.'},';
}
//convert array into a single string variable
$markers = implode( ' ', $markers );
//remove the end comma in the string
$markers = substr_replace($markers,"",-1);
$jscript = 'var markers; markers =' .'[' .$markers .'];';
print $jscript;
?>
there's a working example of this query at :
http://www.nl-webspace.co.uk/~unn_p9218 ... ndpubs.php
both map_data2.php scripts are ididentical except for a few lines of code at the start:
Code: Select all
<?php
require_once('common.php');
db_connect();
// remove any harmless run-time notices
error_reporting(E_ALL ^ E_NOTICE);
foreach($_GET as $key=>$value) {
if ($value !== ''){
$chkbox_arr[]=' AND Amenities.'.$key."='y'";
}
}
...