Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-14-2010, 07:26 AM php syntax
Ultra Talker

Posts: 254
Trades: 0
i would like to display statistics information and show this on a map with multiple markers

i have initially created for a single marker the example is at
http://www.sudhakargolakaram.co.in/files/stats.php

for this i have written the following in the php file


PHP Code:
echo ('
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

<script src="maps api key"></script>
    
<script src="jquery.googlemaps1.01.js"></script>
'
);

$lat="-36.847385";
$lon="174.765735";

echo(
'
<script type="text/javascript"> 
    $(document).ready(function() { 
        $("#map_canvas").googleMaps({
            markers: {
                latitude:     '
); echo $lat; echo(',
                longitude: '
); echo $lon;
            echo(
' }
        }); 
    }); 
</script> 
'
);
?> 
this is working fine

however i would like to get the values of the latitude and longitude values from mysql using select query and pass the values of latitude and longitude to the javascript code using a while loop

the code to display multiple markers is

HTML Code:
<script type="text/javascript"> 
	$(document).ready(function() { 
		$('#map_canvas').googleMaps({
			markers: [{
				latitude: 	37.4416,
				longitude: -122.1516
			},{
				latitude: 	37.4516,
				longitude: -122.1616
			},{
				latitude: 	37.4566,
				longitude: -122.1666
			}]
		}); 
	}); 
</script>
this multiple markers is quite different to single marker as this does not have },{ for the last marker

in terms of the syntax of the php code how can i write the php code so that i will get the output in the browser as mentioned above for multiple markers

thanks

Last edited by chrishirst; 09-14-2010 at 02:46 PM..
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-17-2010, 01:04 AM Re: php syntax
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try something like this:

PHP Code:
<script type="text/javascript">
    $(document).ready(function() {
        $('#map_canvas').googleMaps({
            markers: [<?php
$sql 
"SELECT lat, long FROM geo_table";
if (
$a_query $db->query($sql)) {
  if (
$a_query->num_rows0) {
    
$a_row_prefix '';
    while (
$a_row $a_query->fetch_object()) {
      echo 
$a_row_prefix.'
      {
                latitude : '
.$a_row->lat.',
                longitude: '
.$a_row->long.'
            }'
;
            
$a_row_prefix ',';
    }
  }
}
?>]
        });
    });
</script>
By having a prefix that starts out as an empty string and then is thereafter set as the separator, a comma, you can add commas only as needed.

Hope that helps.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 09-17-2010, 01:42 AM Re: php syntax
Ultra Talker

Posts: 254
Trades: 0
thanks
sudhakararaog is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php syntax
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17850 seconds with 12 queries