如何修复意外的$end错误


How to fix unexpected $end error?

你好,我学习使用PHP创建门户新闻,我一步一步地学习了书籍教程。但它总是给我一个返回错误:(

我一遍又一遍地检查我的语法,我的代码与书中的教程相同。 我想我找不到这个错误。 如果有人能帮助我,将不胜感激。

<link rel="stylesheet" type="text/css" href="style.css"/>
<?php
include 'koneksi.php';
$table1=berita;
$table2=kategori;
$id=1;
$hal = $_GET[hal];
if(!isset($_GET['hal'])){
$page = 1;
}else {
$page = $_GET['hal'];
}
$max_result = 2;
echo $page;
$from = (($page * $max_result) - $max_result);
$sql=mysql_query("select * from $table1, $table2 where $table1.id_kategori and $table1.id_kategori=$table2.id_kategori order by tanggal desc limit $from, $max_result;");
while($tampil=mysql_fetch_array($sql)){
$data=substr($tampil['isi'],0,200);
?>
<div class="box">
<p align="justify">
<img src="<?=$tampil[gambar];?>" align="left">
<font valign="top">
<strong><?php echo $tampil[judul]; ?></strong>"
<?php echo $data;?>
<a href="index.php?menu=detail_politik&id=<?=$tampil['id_berita'];?>">Baca Selengkapnya-->>>></a>
</font></p></div><br>
<?php
}
$total_results = mysql_result(mysql_query("select count(*) as Num from $table1 where $table1.id_kategori=$id"),0);
$total_pages = ceil($total_results/$max_result);
echo "<center>Pilih Halaman<br/>";
if($hal > 1){
$prev = ($page - 1);
echo "<a href=$_SERVER[PHP_SELF]?menu=politik&hal=$prev><-sebelumnya</a>";
}
for($i = 1; $i <=$total_pages; $i++){
if(($hal) == $i){
echo "$i";
}else{
echo "<a href=$_SERVER[PHP_SELF]?menu=politik&hal=$i>$i</a>";
}
if($hal < $total_pages){
$next = ($page + 1);
echo "<a href=$_SERVER[PHP_SELF]?menu=politik&hal=$next>selanjutnya-></a>";
}
echo "</center>"
?>

这段代码总是给我错误:解析错误:语法错误,C:''AppServ''www''beritaonline''filepolitik.php 第 48 行中的意外$end

48 上的行是:最后一行代码,?>

亲爱的怎么了:'((

您需要

在最后一个echo后添加分号;

echo "</center>";
?>

在大多数情况下,您也不需要?>结束 php 标签。

此外,您的for循环没有闭合}

for($i = 1; $i <=$total_pages; $i++){

这将引发错误。

您的下一个循环不会以 } 结束

顺便说一句,最后一行中也缺少 a ;