你好,我学习使用php创建门户新闻,我在本书的教程中逐步进行了跟踪。但是它总是给我返回错误:(
iam一次又一次地检查我的语法,我的代码与书中的教程相同。我想我找不到此错误。如果有人可以帮助我,将不胜感激。
<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>"
?>
这段代码总是给我错误:解析错误:语法错误,第48行的C:\ AppServ \ www \ beritaonline \ filepolitik.php中出现意外的$ end
而第48行是:代码的最后一行,?>
亲爱的怎么了:'((
您需要;
在最后一个末尾添加分号echo
:
echo "</center>";
?>
在大多数情况下,您也不需要关闭php标签?>
。
另外,您的for
循环没有关闭}
:
for($i = 1; $i <=$total_pages; $i++){
这将引发错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句