There are two questions: 1) how to get what I need from the database. 2) how to convey what I received from the database in javascript, I have an html file. it contains javascript map.js and the map.php file. The Java script runs fine, but the PHP file doesn't seem to run. I don’t know how to bind Javascript and PHP together in an html file. I haven’t studied PHP and Javascript, I have a slightly different specialization, but now, out of necessity, I have to write something.

here is the map.php code:

here from the database I need to get an array of elements coordinate 1 and coordinate 2 example of array element format

then this array needs to be passed to javascript, here it is already initialized, but it needs to be filled from the database. The array is called markers. map.js

Var map; var point = 1; //points for the engine var markers = ( point1:, point2:, point3:, point4:, point5:, point6:, point7:, point8:, point9:, point10:, ); $(document).ready(function())( //map 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); //mark all points on the map var marker = ; for(i in markers)( marker[i] = new google. maps.Marker(( position: new google.maps.LatLng(markers[i], markers[i]), map: map )); //map.panTo(new google.maps.LatLng(markers.point10, markers .point10)); //map engine by points function mover())( map.panTo(new google.maps.LatLng(markers["point"+point], markers["point"+point])); point ++ ; if(point>10)point=1; ) //map is not used google.maps.event.addListener(map, "idle", function())( setTimeout(mover, 500);//time in milliseconds )); ));

P.S. Since due to lack of points there is no way to upvote or answer, I will write here. I thank the Inkognitoo user, dekameron, for his help. I got what I wanted to implement. Everything works. I used the idea of ​​decameron. This is the first or second time I’m working with PHP. I for a long time I bought it, what is the essence and why it doesn’t work, it turns out I had an html file and in it and also then I made index.php and put the html in echo, and also put javascript in echo. and inserted var markers in the right place. In general, thank you all for your help and time spent.

BUT Deonisa's SOLUTION turned out to be better because you don't have to stuff everything into echo, you can use html page and everything will be neat and clean. This really won't be shit code.

http://www.wiseguys.com.ua/ here is a ready-made solution, well, this is only part of what I am planning, but it’s good that one piece is ready. I'm not a web developer at all, I work with Android OS.

I have a file with the extension php. Here I read the information from the database. And I need to pass this data (associated array) to js which is also included in this php file.

const arr = JSON.parse(""); console.log(arr);

array(5) ( => array(7) ( ["id"]=> string(1) "1"["question"]=> string(143) "The ______________ of a table is used to modify the design of a table, like modifying the name of a field or changing the data type of a field."["answer1"]=> string(14) "Datasheet View"["answer2"]=> string(11) "Desisn View" ["answer3"]=> string(10) "Table View"["answer4"]=> string(11) "Wizard View"["true_answer"]=> string(1) "1") => array(7 ) ( ["id"]=> string(1) "2"["question"]=> string(83) "You can select multiple fields of a table in design view by using the ________ key."["answer1" ]=> string(3) "Alt"["answer2"]=> string(8) "Spacebar"["answer3"]=> string(5) "Shift"["answer4"]=> string(4) " Ctrl"["true_answer"]=> string(1) "3") ... Uncaught SyntaxError: missing) after argument list

Conclusion:
Co php sides Everything is fine. But when we try to parse this array in the js object in the js part, we see a strange error.

  • How to load data (like an associated array in my case) from php to js. When php and js are in the same extension file (php).
  • How to load data (like an associated array in my case) from php to js. When php and js are in different files. For example, we have 1 php extension file in which we have implemented the logic (in my case it is DB). And we need to import this data into a js extension file.
  • Solution

    1) All you need to do is:

    var arr = ; // alert(questions); // Output whatever is in the questions-variable

    questions will be a global JS variable that you can reach
    from another js.file or from js embedded in an html file.

    // As data in your html:


    Close