error on php/javascript script
Posted: Sat Nov 04, 2006 6:43 pm
i'm tring to create a javascript data structure which contains data pulled out of a database via php. the data is reformated and i'm attempting to echo the data structure back out to the browser. the problem is i keep getting an error stating: "undefined variable: markers in /.../map_data.php on line 34 var markers "
please somone take a look and advice me on how i can proceed as i've hit a brick wall. thank you.
please somone take a look and advice me on how i can proceed as i've hit a brick wall. thank you.
Code: Select all
<?php
function getPubMarkers() {
db_connect();
$sql = mysql_query ( " select Longitude, Latitude, pubName, pubStreetNo, pubStreet, pubCity, pubCounty,
pubPostcode, pubPhone from Pubs " ) or die( 'Invalid query: ' . mysql_error() );
while( $elements = mysql_fetch_array($sql) ) {
$markers[] = '{'
." 'lng': " .$elements[0] .','
." 'lat': " .$elements[1] .','
." 'name': " .$elements[2] .','
." 'address': " .$elements[3] .'<br>' .$elements[4] .'<br>' .$elements[5]
.'<br>' .$elements[6] .'<br>' .$$elements[7] .','
." 'phone': " .$element[8]
.'},';
}
//convert array into a single string variable
$markers = implode( ' ', $markers );
//remove the end comma in the string
$markers = substr_replace($markers,"",-1);
}
echo 'var markers
markers ='
.'['
.$markers // line 34
.'];';
?>