1

I am new to web technologies and I want to create a web app that allows a user to click on a map and a form will pop up and it will allow him to enter certain information. That information is saved on a database. Now I don't know how to pull that information because I need to create markers on the map with the longitude and latitude as its position. I don't know how to pass values from php variables to javascript

<?php
    require_once("mysqli_connect.php");

    $query = "SELECT * FROM markeri";

    $response = @mysqli_query($dbc, $query);

    if($response){
        while($row = mysqli_fetch_array($response)){
            $naziv = $row['naziv'];
            $opis = $row['opis'];
            $email = $row['email'];
            $latitude = $row['latitude'];
            $longitute = $row['longitute'];


        }
    }

?>

This is the code for pulling data from the database. Now I need to create markers on the map with all the information from the database.

var marker = L.marker(e.latlng);
marker.addTo(mymap).bindPopup(form).openPopup();

<div id="form">
    </br>
    Naziv:</br>
    <h1 id="naziv"></h1></br></br>
    Opis problema:</br>
    <p id="opis"></p> </textarea></br>
    E-mail:</br>
    <h3 id="email"> </h3></br></br>
</div>

I am using the Leaflet API for interaction with the map. I need to create markers by replacing e.latlng(which is a JS array) with latitude and longitude pulled from the database with PHP and to make a marker at that position. I need to fill the information in the "form" above as well for each individual marker.

This is the table in the database: enter image description here

3
  • 2
    Using Ajax? After save, do AJAX request to PHP which will return JSON you need. And then just populate data into HTML. Commented Nov 20, 2016 at 15:19
  • @MykolaBorysyuk How would you do that ? I don't know how to store the information that I looped through. Commented Nov 20, 2016 at 15:39
  • On a curious note, why is this question voted down? Commented Mar 28, 2017 at 22:57

1 Answer 1

1

if you have Jquery just do http://api.jquery.com/jquery.ajax/

$.ajax({
  method: "GET",
  url: "some.php"
})
.success(function(res) {
    //If all ok you will get Object as a responce
    console.log(JSON.parse(res));
});

Insode you some.php script $data is object that you need.

echo json_encode($data);

Now just in success handler. Loop and add elements into table, div,whatever using JQuery or pure JavaScript.

Looks like this. http://api.jquery.com/append/

$( "p" ).append( "<strong>Hello</strong>" );

You may want to check other methods. This is just example.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.