-3

i was check all but i am confused for mixing this code with PHP and HTML , Parse error: syntax error, unexpected end of file

</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="jquery.js"></script>
<script type="text/javascript">
(function() {
window.onload = function() {
var map;
var locations = [
<?php
     //konfgurasi koneksi database 
      mysql_connect('localhost','root','');
      mysql_select_db('candralab-map');

            $sql_lokasi="select idlokasi,lat,lon
            from lokasi  ";
            $result=mysql_query($sql_lokasi);
            // ambil nama,lat dan lon dari table lokasi
            while($data=mysql_fetch_object($result)){
                 ?>
         ['<?=$data->idlokasi;?>', <?=$data->lat;?>, <?=$data->lon;?>],
   <?
            }
?>
];

var options = {
  zoom: 12, //level zoom
  //posisi tengah peta
  center: new google.maps.LatLng(-7.8008, 110.380643),
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById('peta'), options);
  var infowindow = new google.maps.InfoWindow();

var marker, i;
for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
     icon: 'icon.png'
  });       
        google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() { 
            var id= locations[i][0];
            $.ajax({
                url : "get_info.php",
                data : "id=" +id ,
                success : function(data) {
                        $("#info").html(data);
                }
            });     
        }
    })(marker, i));
}
};
 })();</script>

can u find the missing part ?because mixing PHP and HTML is confusing, plese help me for fix this code...

Faza Adhzima
  • 45
  • 1
  • 7
  • This isn't the full code, so really can't help you. But get a good IDE/Editor with syntax highlighting and error checking, and it should guide you to the right area. – aynber Feb 08 '18 at 19:33
  • 1
    **obligatory note** mysql_* functions are deprecated as of PHP 5.5.0, and removed as of PHP 7.0.0. Switch your code to use [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) or [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. – aynber Feb 08 '18 at 19:34
  • I recommend a different approach: building the array in PHP and then using [`json_encode`](http://php.net/manual/en/function.json-encode.php) for use in JavaScript. See [Convert php array to Javascript](https://stackoverflow.com/questions/5618925/convert-php-array-to-javascript#answer-5619038). Alternatively, you could fetch the data from your PHP script by using [AJAX](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX). – showdev Feb 08 '18 at 19:41

1 Answers1

0

The problem is with this part of your code:

   <?
            }
?>

You're using a mix of regular and short tags. But that short tag is incomplete (it is missing the = sign). You should change this to:

   <?=
            }
?>

That will fix your problem.

pbarney
  • 2,529
  • 4
  • 35
  • 49