大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
简单的有两种做法
成都网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站设计等服务项目。核心团队均拥有互联网行业多年经验,服务众多知名企业客户;涵盖的客户类型包括:玻璃钢坐凳等众多领域,积累了大量丰富的经验,同时也获得了客户的一致认可!
一、直接在SQL语句上通过limit 的参数
二、全部取出,在结果集数组上通过数组位来控制
其实两种玩法本质上一样
?
//设置当前页显示的数量(这个数量可任意设置)
$limit=20;
//初始化数据库搜索起始记录
if (!empty($start)) $start=0;
mysql_connect("localhost","","");
mysql_select_db(database);
//设置数据库记录总数
$result=mysql_query("select * from table");
$num_max=mysql_numrows($result);
$result=mysql_query("select * from table order by id desc limit $start,$limit);
$num=mysql_numrows($result);
echo "tabletrtd翻页功能/td/tr";
if (!empty($num)) {
for ($i=0;$i$num;$i++) {
$val=mysql_result($result,$i,"val");
$val1=mysql_result($result,$i,"val1");
echo "trtd$val/tdtd$val1/td/tr";
}
}
echo "trtd";
//设置向前翻页的跳转
$prve=$start-$limit;
if ($prve=0) {
echo "a href=page.php?start=$prveprve/a";
}
//设置向后翻页的跳转
$next=$start+$limit;
if ($next$num_max) {
echo "a href=page.php?start=$nextnext/a";
}
echo "/td/tr/table";
?
不是用$_POST[]的,用$_GET[]
不是表单传值,而是链接传值
if( isset($_GET['page']) $_GET['page']!=1){
$page = intval( $_GET['page'] );
$pageSize = 50;
}else{
$page = 1;
$pageSize = 50;
}
if( $page == 0 ){
$link = "a href=?page=".($page+1)."下一页/a";
}
elseif( $page != 0 $page !=1 ){
$link = "本页第 ".$page." 页 a href=?page=1首页/a | a href=?page=".($page-1)."上一页/a | a href=?page=".($page+1)."下一页/a";
}else{
$link = "本页第 ".$page." 页 a href=?page=1首页/a | a href=?page=".($page+1)."下一页/a";
}
那是因为你没有把搜索的参数传过去
你可以写一个隐藏域传递或者直接用搜索的TEXT传过去(再跳转的时候一定要接收到这个关键字,然后把这个关键字再当做搜索框的value值)。然后每次都要用到这个关键字。
也可以把关键字放到session里面,这样就不用传来传去了。但是也是每一次都一定要用这个关键字的
建议你先还是用其他办法作吧!我从phpaaCMS弄了个分页·蛮好的:
?php
include("conn.php");
function selectLimit($sql, $numrows=-1, $offset=-1) {
if($offset==-1){
$sql .= ' LIMIT ' . $numrows;
}else{
$sql .= ' LIMIT ' . $offset . ', ' . $numrows;
}
$res = mysql_query ( $sql );
if ($res !== false) {
$arr = array ();
$row = mysql_fetch_assoc ( $res );
while ($row) {
$arr [] = $row;
$row = mysql_fetch_assoc ( $res );
}
return $arr;
} else {
return false;
}
}
function getArticleList($str=''){
global $db;
$curpage = empty($_GET['page'])?0:($_GET['page']-1);
//定义默认数据
$init_array =array(
'row' =0,
'titlelen' =0,
'keywords' =0,
'type' ='',
'cid' ='',
'order' ='id',
'orderway' ='desc'
);
//用获取的数据覆盖默认数据
$str_array = explode('|',$str);
foreach($str_array as $_str_item){
if(!empty($_str_item)){
$_str_item_array = explode('=',$_str_item);
if(!empty($_str_item_array[0])!empty($_str_item_array[1])){
$init_array[$_str_item_array[0]]=$_str_item_array[1];
}
}
}
//定义要用到的变量
$row = $init_array['row'];
/* $titlelen = $init_array['titlelen'];
$keywords = $init_array['keywords'];
$type = $init_array['type'];
$cid = $init_array['cid'];
$order = $init_array['order'];
$orderway = $init_array['orderway'];*/
//文章标题长度控制
if(!empty($titlelen)){
$title="substring(a.title,1,".$titlelen.") as title";
}else{
$title="a.title";
}
//根据条件数据生成条件语句
$where = "";
if(!empty($cid)){
$where .= " and a.cid in (".$cid.")";
}else{
if(isset($_GET['id'])!empty($_GET['id'])is_numeric($_GET['id'])){
$where .= " and a.cid in (".$_GET['id'].")";
}
}
if($type=='image'){
$where .= " and a.pic is not null";
}
if(!empty($keywords)){
$where .= " and a.title like '".$keywords."%' or a.content like '".$keywords."%'";
}
$sql = "select * from news order by datetime desc";
global $pageList;
$query = mysql_query("SELECT * FROM `news`");
$total = mysql_num_rows($query);
$pageList['pagination_total_number'] = $total;
$pageList['pagination_perpage'] = empty($row)?$pageList['pagination_total_number']:$row;
return selectLimit($sql,$pageList['pagination_perpage'],$curpage*$row);
}
function getArticleInfo($page_url,$page = 8) {
global $pageList;
//当前第几页
$curpage = empty($_GET['page'])?1:$_GET['page'];
$realpages = 1;
if($pageList['pagination_total_number'] $pageList['pagination_perpage']) {//需要分页
$offset = 2;
//实际总分页数
$realpages = @ceil($pageList['pagination_total_number'] / $pageList['pagination_perpage']);
$pages = $realpages;
if($page $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from $page) {
$to = $page;
}
} elseif($to $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$phpaa_page = '';
$page_url .= strpos($page_url, '?') ? '' : '?';
$phpaa_page = ($curpage - $offset 1 $pages $page ? 'a href="'.$page_url.'page=1" class="first"首页/a ' : '').
($curpage 1? 'a href="'.$page_url.'page='.($curpage - 1).'" class="prev"上一页/a ' : '上一页');
for($i = $from; $i = $to; $i++) {
$phpaa_page .= $i == $curpage ? 'strong style="color:#ffa000"'.$i.'/strong ' :
'a href="'.$page_url.'page='.$i.($i == $pages ? '#' : '').'"'.$i.'/a ';
}
$phpaa_page .= ($to $pages ? 'a href="'.$page_url.'page='.$pages.'" class="last"...'.$pages.'/a ': '');
$phpaa_page .= ($curpage $pages ? 'a href="'.$page_url.'page='.($curpage + 1).'" class="next"下一页/a ' : '下一页');
$phpaa_page .= ($to $pages ? 'a href="'.$page_url.'page='.$pages.'" class="last"尾页/a ': '');
$phpaa_page = $phpaa_page ? 'div class="pages"共 '.$pageList['pagination_total_number'].' 条 '.$phpaa_page.'/div' : '';
}
return $phpaa_page;
}
?
?php foreach(getArticleList("cid=".$_GET['id']."|row=2") as $list){?//需要分多少页
tr
td height="30" align="left"a href="html/?php echo $list['id'].".html"?" target="_blank"?php echo $list['title']?/a /tdbr
/tr
?php
}
?
?php echo getArticleInfo("fenye.php?id=".$_GET['id']);?//你所需要分页页面的url