日期:2014-05-16 浏览次数:20483 次
<?php
include('db_class.php');
include('inc/function.php');
$keyword=trim($_POST['keyword']);
if($keyword==""){
echo "<script>alert('请输入新闻名称!'); history.go(-1);</script>";
exit;//结束程序
}
// 数据库查找代码
$page=isset($_POST['page'])?intval($_POST['page']):1;
$num=2;
$total=$db->getcount("select * from `".$prefix."newsbase` where id like '%{$keyword}%' or title like '%{$keyword}%' ");
//页码计算
$pagenum=ceil($total/$num); //获得总页数,也是最后一页
$page=min($pagenum,$page);//获得首页
$prepg=$page-1;//上一页
$nextpg=($page==$pagenum ? 0 : $page+1);//下一页
$offset=($page-1)*$num;
$result=$db->query("select * from `".$prefix."newsbase` where sn like '%{$keyword}%' or title like '%{$keyword}%' or author like '%{$keyword}%' order by news_id desc");
if($row=mysql_num_rows($result)){
while($row=$db->getarray($result)){
?>
<tr>
<td class="font" valign="top" width="130"><?php echo $row[id]; ?></td>
<td class="font" valign="top" width="130"><?php echo $row[title]; ?></td>
<td class="font" valign="top" width="130"><?php echo $row[author]; ?></td>
</tr>
<?php
}
} else{
echo "<script>alert('没有该新闻信息!'); history.go(-1);</script>";
exit;//结束程序
}
?>
<?php
include 'inc/fy.php'; //分页类
$page=new page(array('total'=>$total,'perpage'=>$num));
echo $page->show(3);
?>