如何最好地将 mysql 数据实现到一行 javascript 代码中?
我正在修改 Google 地图的一些 javascript,以便从我的数据库中检索不同的 pin 信息。如果我只用 php 来做这件事,它会是这样的:
<?php while($row = mysql_fetch_assoc($query))
{$title = $row['title']; $desc = $row['desc']; echo 'This '.$title .' and this '. $desc .';}?>
如果数据库中有 5 行,那么将有 5 行有 5 个不同的标题和描述。 但我有这行 javascript,我想在 while 循环中:
map.addMarkerByLatLng(37.8685, -1.5108, "Sanatario de Terburculosos", createInfo("title goes here",""));
我怎样才能编写它,以便该 javascript 位于 php while 循环中,或者我怎样才能执行 php while 循环的 javascript 等效项,以便我可以像上面一样,在自己的 javascript 代码中检索多行 lang、lat 信息?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ajax.php
jquery ajax
ajax.php
jquery ajax
结合您提供的两个代码示例:
Combine the two code examples you have provided: