There are two questions: 1) how to get what I need from the database. 2) how to pass, what I got from the database in javascript I have an html file. It includes javascript map.js and the file map.php. Java script is normally executed, and pkhp file is not executed like. How to bind javascript and pkhp together in an html file, I do not know. I did not study PCP and javascript, I have a slightly different specialization, but now I have to write something by necessity.
Here is the code map.php:
<?php $hostname = "***************"; $username = "****************"; // имя пользователя (в Denwer`е по умолчанию "root") $password = "**********"; $dbName = "***********"; $table = "test_table"; mysql_connect($hostname, $username, $password) or die ("Не могу создать соединение"); mysql_select_db($dbName) or die (mysql_error()); $query = "SELECT coord1,coord2 FROM $table"; $res = mysql_query($query) or die(mysql_error()); mysql_close(); ?>
here from the base I need to get an array of elements of the coordinate 1 and coordinate 2 an example of the format of the element of the array [54.345324,23.4354353]
then this array needs to be transferred to javascript, here it is already initialized in me, but you need to fill it from the base. The array is called the markers. map.js
var map; var point = 1; //точки для двигателя var markers = { point1:[55.755786, 37.617633], point2:[55.7543712, 37.6104643], point3:[55.7531491, 37.6101551], point4:[55.7506212, 37.6101143], point5:[55.7541852, 37.5274149], point6:[55.7473746, 37.609723], point7:[55.803607, 37.328598], point8:[55.7422534, 37.6064208], point9:[55.7397707, 37.6055861], point10:[55.704945, 37.5277036], }; $(document).ready(function(){ //карта var latlng = new google.maps.LatLng(55.755786, 37.617633); var myOptions = { zoom: 13, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); //отмечаем все точки на карте var marker = []; for(i in markers){ marker[i] = new google.maps.Marker({ position: new google.maps.LatLng(markers[i][0], markers[i][1]), map: map }); } //map.panTo(new google.maps.LatLng(markers.point10[0], markers.point10[1])); //двигатель карты по точкам function mover(){ map.panTo(new google.maps.LatLng(markers["point"+point][0], markers["point"+point][1])); point ++; if(point>10)point=1; } //карта не используется google.maps.event.addListener(map, 'idle', function(){ setTimeout(mover, 500);//время в милисекундах }); });
PS since, due to the lack of points, there is no possibility of a plus or answer, I will write here. I thank user Inkognitoo , dekameron for help. I got what I wanted to implement. Everything is working. I used the idea of decameron.the first or second time I work with php. I bought for a long time what the point was and why it does not work, it turns out I had an html file and in it <? ?> and also <script> then I did index.php and drove html into echo, also javascript drove into echo. and in the right place pasted var markers. In general, thank you all for your help and your time.
BUT DECISION Deonisa turned out to be better because you do not have to put everything in echo, you can use the html page and everything will be neat and clean. indeed it will not be a code.
http://www.wiseguys.com.ua/ here is a ready-made solution, well, this is only part of what I plan, but it’s already good that one piece is ready. I am not a web developer at all, I work with Android OS.