一. 某部分功能需要jquery的支持 二. 分页代码固定为page 支持自动获取queryString哦. 我一般是 $this-pagination(............) 具体效果可以参考http://www.limian.com/today/winner 不过css不是我写的...有错见谅不全见谅 既然要css我就把css贴上吧 无 /**
一. 某部分功能需要jquery的支持
/** * @author: LiaoJiangYi * 分页代码 pagination * @param $num int 总共有多少条记录 * @param $perpage int 每页显示多少条数据 * @param $curpage int 当前页数 * @param $anchor string URL附加参数 例:&a=1&b=2 * @param $page_href_template string 例:{url}/{page}.html */ public function pagination($num, $perpage, $curpage, $anchor='', $page_href_template = '',$otherJsFunc = '') { $multipage = ''; $curpage = $curpage>1 ? $curpage : 1; if (!empty($_SERVER['QUERY_STRING'])) $REQUEST_URI = $_SERVER['QUERY_STRING'] ? $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'] : $_SERVER['PHP_SELF']; $mpurl = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $REQUEST_URI; if(!$page_href_template) { $_parse_url = parse_url($mpurl); $url_query = !empty($_parse_url["query"]) ? $_parse_url["query"] : ''; if($url_query) { $url_query = explode('&',$url_query); $querys = ''; foreach($url_query as $val) { $val = explode('=',$val); $k = $val[0]; $v = $val[1]; $v = htmlspecialchars(strip_tags(trim($v)),ENT_QUOTES,'UTF-8'); $k = htmlspecialchars(strip_tags(trim($k)),ENT_QUOTES,'UTF-8'); $v = str_replace("'",'',$v); $v = str_replace('"','',$v); $v = str_replace("\\",'',$v); if($k!='page')$querys .= $k.'='.$v.'&'; } $mpurl = $_parse_url['path'].'?'.$querys; unset($querys,$v,$k,$val); }else $mpurl.="?"; unset($url,$url_query,$_parse_url); } else { $ae = pathinfo($mpurl); $mpurl = $ae["dirname"]; unset($ae); } if($num > $perpage) { $page = 5; $offset = 2; $pages = @ceil($num / $perpage); if($page > $pages) { $from = 1; $to = $pages; } else { $from = $curpage - $offset; $to = $curpage + $page - $offset - 1; if($from < 1) { $to = $curpage + 1 - $from; $from = 1; if(($to - $from) < $page && ($to - $from) < $pages) { $to = $page; } } elseif($to > $pages) { $from = $curpage - $pages + $to; $to = $pages; if(($to - $from) < $page && ($to - $from) < $pages) { $from = $pages - $page + 1; } } } if(!$page_href_template) { $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1'.$anchor.'" class="p_redirect">首 页</a>' : '').($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).$anchor.'" class="p_redirect">上一页</a>' : ''); for($i = $from; $i <= $to; $i++) { $multipage .= $i == $curpage ? '<span class="p_curpage" >'.$i.'</span>' : '<a href="'.$mpurl.'page='.$i.$anchor.'" class="p_num">'.$i.'</a>'; } $multipage .= ($curpage!=$pages && $pages>$page) ? '....... <a href="'.$mpurl.'page='.$pages.$anchor.'" class="p_num">'.$pages.'</a>' : ''; $multipage .= ($curpage < $pages ? '<a href="'.$mpurl.'page='.($curpage + 1).$anchor.'" class="p_redirect">下一页</a>' : '').($to < $pages ? '<a href="'.$mpurl.'page='.$pages.$anchor.'"class="p_redirect">尾 页</a>' : ''); } else { $mpurl = str_replace('{url}',$mpurl,$page_href_template); $multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.str_replace('{page}',1,$mpurl).'" class="p_redirect">首 页</a>' : '').($curpage > 1 ? '<a href="'.str_replace("{page}",($curpage - 1),$mpurl).'" class="p_redirect"><上一页</a>' : ''); for($i = $from; $i <= $to; $i++) { $multipage .= $i == $curpage ? '<span class="p_curpage" >'.$i.'</span>' : '<a href="'.str_replace("{page}",$i,$mpurl).'" class="p_num">'.$i.'</a>'; } $multipage .= ($curpage!=$pages && $pages>$page) ? '... <a href="'.str_replace('{page}',$pages,$mpurl).'" class="p_num">'.$pages.'</a>' : ''; $multipage .= ($curpage < $pages ? '<a href="'.str_replace('{page}',($curpage + 1),$mpurl).'" class="p_redirect">下一页></a>' : '').($to < $pages ? '<a href="'.str_replace("{page}",$pages,$mpurl).'"class="p_redirect">尾 页</a>' : ''); } } $multipage = $multipage;//.'<span class="p_bar"><span class="p_info">共'.$num.'条记录</span> 每页显示'.$perpage.'条</span>'; if($otherJsFunc) { $pages = !empty($pages) ? $pages : 1; $pages = $pages < 1 ? 1 : $pages; $multipage .= '共'.$pages.'页 到第<input type="text" id="'.$otherJsFunc.'_page" value="'.$curpage.'" class="page_text">页<input type="button" class="page_btn" onclick="'.$otherJsFunc.'($(\'#'.$otherJsFunc.'_page\').val())" value="确定">'; } //$multipage = '<span class="p_info">共'.$num.'条</span>'.$multipage; return $multipage; }
/*------------------------分页------------------------------*/ .div_pages { text-align: right; margin: 25px 0 5px 0; font-family: '宋体' } .div_pages a, .p_curpage { height: 24px; border: 1px solid #e3e3e3; background: #f8f8f8; color: #666666; display: inline-block; text-align: center; line-height: 25px; min-width: 15px; padding: 0 5px; margin: 0 2px; } .div_pages a.page_select { color: #fff; background: #CC374B; border: 1px solid #cc0004; } .div_pages a:hover { color: #cc0004; border: 1px solid #cc0004; background: #fff; } .div_pages .page_text { width: 34px; height: 16px; border: 1px solid #cccccc; padding: 4px 2px; margin: 0 5px; vertical-align: middle; text-align: center; } .div_pages .page_btn { width: 50px; height: 26px; background: url("/cdn/today/images/page_btn.jpg") no-repeat; border: 0; margin: 0 5px; cursor: pointer; vertical-align: middle; margin-right: 18px; }