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