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

混合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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同