cara memindahkan data php ke js yang benar ?

selamat malam gan, gimana cara yang benar agar saya dapat memindahkan data $row database di PHP ke javascript ?

code PHP saya



<!DOCTYPE html>
<html>
   <head>
      <title>Leaflet sample</title>
      <link rel = "stylesheet" href = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
      <script src = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
   </head>
   <body>
      <?php
        $host = 'localhost';
        $user = 'ivan';
        $pass = 'ivan';
        $db = 'db_map';

                $con = mysqli_connect($host,$user,$pass,$db);
                if(!$con){
                    echo 'error connect to database !';
                }
                $sql = "SELECT * FROM tb_map";
                $result = mysqli_query($con, $sql);


                while($row = mysqli_fetch_array($result)){
                    $row1 = $row[0];
                    $row2 = $row[1];
                    $row3 = $row[2];
                    $row4 = $row[3];

                    //echo $row1 ." ". $row2 ." ". $row3 ." ". $row4 ."<br>";
                    //json_encode($row);
                }

      ?>
</script>
      <div id = "map" style = "width: 900px; height: 580px"></div>
      <script src="script.js"></script>
   </body>
</html>

avatar ivanpratama99
@ivanpratama99

88 Kontribusi 12 Poin

Dipost 6 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban