首页 > 网站 > 建站经验 > 正文

phpcms v9自定义数据分页代码分享

2024-04-25 20:35:25
字体:
来源:转载
供稿:网友

研究phpcms v9解决的问题,分享给大家,希望对大家有所帮助,来自B5教程网额分享。

public function s_q()

{

global $db;

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$pagesize = 10;

$start_rs=($page-1)*$pagesize;

$q = safe_replace(trim($_GET['q']));

$q = new_html_special_chars(strip_tags($q));

$q = str_replace('%', '', $q); //过滤'%',用户全文搜索

$sql="select * from pm_ss WHERE stitle like '%$q%'";

$result =$this->db->query($sql);

$data=$this->db->fetch_array();

$num=count($data);

$sql2="select * from pm_ss WHERE stitle like '%$q%' limit ".$start_rs.",".$pagesize."";

$re =$this->db->query($sql2);

$das=$this->db->fetch_array();

$pages=$this->pages($num,$page,$pagesize);

include template('search','list');

}

function pages($num, $curr_page, $perpage = 20, $urlrule = '', $array = array(),$setpages = 10) {

if(defined('URLRULE') && $urlrule == '') {

$urlrule = URLRULE;

$array = $GLOBALS['URL_ARRAY'];

} elseif($urlrule == '') {

$urlrule = url_par('page={$page}');

}

$multipage = '';

if($num > $perpage) {

$page = $setpages+1;

$offset = ceil($setpages/2-1);

$pages = ceil($num / $perpage);

if (defined('IN_ADMIN') && !defined('PAGES')) define('PAGES', $pages);

$from = $curr_page - $offset;

$to = $curr_page + $offset;

$more = 0;

if($page >= $pages) {

$from = 2;

$to = $pages-1;

} else {

if($from <= 1) {

$to = $page-1;

$from = 2;

} elseif($to >= $pages) {

$from = $pages-($page-2);

$to = $pages-1;

}

$more = 1;

}

$multipage .= '<a
class="a1">'.$num.L('page_item').'</a>';

if($curr_page>0) {

$multipage .= ' <a href="'.pageurl($urlrule, $curr_page-1, $array).'" class="a1">'.L('previous').'</a>';

if($curr_page==1) {

$multipage .= ' <span>1</span>';

} elseif($curr_page>6 && $more) {

$multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>..';

} else {

$multipage .= ' <a href="'.pageurl($urlrule, 1, $array).'">1</a>';

}

}

for($i = $from; $i <= $to; $i++) {

if($i != $curr_page) {

$multipage .= ' <a href="'.pageurl($urlrule, $i, $array).'">'.$i.'</a>';

} else {

$multipage .= ' <span>'.$i.'</span>';

}

}

if($curr_page<$pages) {

if($curr_page<$pages-5 && $more) {

$multipage .= ' ..<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';

} else {

$multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';

}

} elseif($curr_page==$pages) {

$multipage .= ' <span>'.$pages.'</span> <a href="'.pageurl($urlrule, $curr_page, $array).'" class="a1">'.L('next').'</a>';

} else {

$multipage .= ' <a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" class="a1">'.L('next').'</a>';

}

}

return $multipage;

}

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表