php搜索加分页
程序员文章站
2022-03-07 16:01:19
...
$wherelist=array(); $urlist=array(); if(!empty($_GET['title'])) { $wherelist[]=" title like '%".$_GET['title']."%'"; $urllist[]="title=".$_GET['title']; } if(!empty($_GET['keywords'])) { $wherelist[]=" keywords like '%".$_GET['keywords']."%'"; $urllist[]="keywords=".$_GET['keywords']; }if(!empty($_GET['author'])) { $wherelist[]=" author like '%".$_GET['author']."%'"; $urllist[]="author=".$_GET['author']; } $where=""; if(count($wherelist)>0) { $where=" where ".implode(' and ',$wherelist); $url='&'.implode('&',$urllist); } //分页的实现原理 //1.获取数据表中总记录数 $sql="select count(*) from news $where "; $result=mysql_query($sql); $totalnum=mysql_num_rows($result); //每页显示条数 $pagesize=5; //总共有几页 $maxpage=ceil($totalnum/$pagesize); $page=isset($_GET['page'])?$_GET['page']:1; if($page $maxpage) { $page=$maxpage; } $limit=" limit ".($page-1)*$pagesize.",$pagesize"; $sql1="select * from news {$where} {$limit}"; //$sql1="select * from news {$where} {$limit}"; $res=mysql_query($sql1); ?>
编号 | 标题 | 关键字 | 作者 | 日期 | 内容 |
首页 "; echo "上一页"; echo "下一页"; echo " 尾页 "; ?> |
上一篇: QT自定义标题栏窗口移动
下一篇: WPF 禁止移动系统标题栏