duanlao6573 2018-02-08 19:30
浏览 92
已采纳

混合PHP和HTML,解析错误:语法错误,意外的文件结尾[重复]

This question already has an answer here:

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...

</div>
  • 写回答

1条回答 默认 最新

  • drsxzut183207938 2018-02-08 19:40
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看