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

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

WBOY
Lepaskan: 2016-06-13 10:54:17
asal
1001 orang telah melayarinya

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>
Salin selepas log masuk

?

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan