final60 Posted August 11, 2011 Share Posted August 11, 2011 I am modifying some javascript for Google maps so that the different pin information is retrieved from my database. If I was to do this with just php it would be like this: <?php while($row = mysql_fetch_assoc($query)) {$title = $row['title']; $desc = $row['desc']; echo 'This '.$title .' and this '. $desc .';}?> If there were 5 rows in the database there will be five lines with 5 different titles and descriptions. But I have this line of javascript that I would like to be in a while loop: map.addMarkerByLatLng(37.8685, -1.5108, "Sanatario de Terburculosos", createInfo("title goes here","")); How can i write it so that that javascript is in a php while loop or how can i do the javascript equivelant of the php while loop so that i can retrieve multiple rows of lang,lat info each in its own javascript code like above? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/244486-how-best-do-i-implement-mysql-data-into-a-line-of-javascript-code/ Share on other sites More sharing options...
sunfighter Posted August 13, 2011 Share Posted August 13, 2011 map.addMarkerByLatLng(37.8685, -1.5108, "Sanatario de Terburculosos", createInfo("<?php echo $title; ?>","")); Puts $title where you want it but some code changes are needed to get all 5 changes into the js. Also a small correction to your code: <?php while($row = mysql_fetch_assoc($query)) { $title = $row['title']; $desc = $row['desc']; echo 'This '.$title .' and this '. $desc; <<== Removed the .' } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244486-how-best-do-i-implement-mysql-data-into-a-line-of-javascript-code/#findComment-1256815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.