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 关于#sql#的问题:#情况描述 在用vs对项目进行调试时,出现找不到网络路径,然后查看SQL配置工具,发现SQL服务显示远程调用过程失败(相关搜索:防火墙)
  • ¥15 主要进行描述泥浆在管路不同区段泥浆的密度不相同,泥浆的密度有高有低,此时管路的摩阻分布需要怎么计算,(标签-matlab)
  • ¥40 通过编制程序计算圆管内层流充分发展对流换热,参数如图5-4,以及公式5-16所示,要求用表5-6对程序计算准确性进行验证
  • ¥20 该学习哪个编程语言? AI会取代程序员吗?
  • ¥15 ensp如何拼通IP地址
  • ¥15 saber软件导入Ibis模型报错
  • ¥15 商城生产日期批次库存问题
  • ¥15 esp8266控制共阳极wrgb灯板无法关闭所有led灯
  • ¥100 python读取速度问题
  • ¥15 stm32f407使用DMA问题