field('id,title')->where("status = 5")-&"/> field('id,title')->where("status = 5")-&">

thinkphp中对数组元素进展分页显示

WBOY
发布: 2016-06-13 10:54:17
原创
1000 人浏览过

thinkphp中对数组元素进行分页显示

 PHP模块代码:class NewsAction extends Action{public $page = '';  //分页,当前页数 function News(){  $list = M("News")->field('id,title')->where("status = 5")->findAll();  //分页   $list = $this->array_page($list);  //结束  $num = 0;  $URL = "http://www.baidu.com/";  $suffixName = '.html';  foreach($list as $key=>$val){   $num = $key + 1;   $str .= '  '.$num.").<a href="%22.%24URL.%24val%5B" id target="_blank">".$val['title']."</a><br> ";  }  $str = preg_replace('/(.*),\s$/','\\1',$str);  $str .= "<div class="d_page">".$this->page."</div>";  return $str; }  //数组分页方法 /** * array  $array 数组 * integer $showCount 每页的记录数 *------------------------------ * return array 返回数组 */ function array_page($array,$listRows = 12,$showCount = 4){  $p = C('VAR_PAGE');  $url  =  $_SERVER['REQUEST_URI']."/".$p."/";  $page  = !empty($_GET[C('VAR_PAGE')])?$_GET[C('VAR_PAGE')]:1;        $upRow   = $page-1;        $downRow = $page+1;    $linkPage = "";  $totalPage = (int)count($array);  $pagetotal = ceil($totalPage/$listRows); //总页数  if($page = $pagetotal) $maxpg = $pagetotal + 1;  }elseif($page > ceil(($showCount)/2) && $page = $pagetotal) $maxpg = $pagetotal;  }elseif($page >=$pagetotal - ceil(($showCount)/2)){   $minpg = $pagetotal - ($showCount-1);   if($minpg == 1) $minpg = 2;   $maxpg = $pagetotal + 1;  }      $linkPage .= " ".$totalPage." 条记录 ".$page."/".$pagetotal." 页 ";    if($pagetotal == 1){   $linkPage .= " <span class="current">1</span> ";  }else{   if($page > 1){    $linkPage .= "  <a href="javascript:void(0)" onclick="\"showpage('".$url."1');\"">第一页</a>";    $linkPage .= "  <a href="javascript:void(0)" onclick="\"showpage('".$url.$upRow."');\"">上一页</a>";   }   for($i = $minpg; $i <font color='\"#FF0000\"'>". $i ."</font>";    }else{     $linkPage .= "  <a href="javascript:void(0)" onclick="\"showpage('".$url.$i."');\"">$i</a>";    }   }   if($page 下一页";    $linkPage .= "  <a href="javascript:void(0)" onclick="\"showpage('".$url.$pagetotal."');\"">最后一页</a>";   }  }       if($listRows page = $linkPage;  if(1 == $pagetotal) $this->page = '';  return $array;   } } 前台Html代码:<script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/artDialog/artDialog.min.js"></script><script language="javascript" type="text/javascript">//分页跳转function showpage(url){ var testDialog; testDialog = dialog('正在加载中...'); $.get(url,null,function(data){  //$("#con").append(data);  testDialog.close();  $("#con").html(data); });}//提示缓冲框function dialog(msg){ var testDialog; testDialog = art.dialog({  lock: false,  title:'',  id:'loaddialog',  content:'<font color="#ff0000">'+msg+'',  width:220 }); return testDialog;}</script><div id="con"></div>
登录后复制

?

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板