標籤:oop sql href [] 底部 foreach 載入 div join
$(document).ready(function() { var totalPage = {$totalPage};//總頁數 var page = {$page}; //起始頁 var pageSize = {$pageSize} //每頁顯示個數 $(window).scroll(function() { if(totalPage-page>0){ //捲軸到達底部載入 if ($(document).scrollTop() >= $(document).height() - $(window).height()) { setTimeout(function() { $.ajax({ type: ‘GET‘, url: ‘?m=wap&c=vedio&a=art_more&typeid=93&yp=128&pageNum=‘+(page+1), success:function(data){ var msg=eval(data); $.each(msg, function (i, item) { $(‘.art-list‘).append("<li><a href="+item.art_link+">"+item.title+"</a></li>"); }); page=page+1; }, error:function(data){ $("#nomore").html("載入失敗..."); setTimeout(function() { $("#nomore").html(); }, 3000); }, }); }, 200); } }else{ $("#nomore").html("我是有底線的..."); setTimeout(function() { $("#nomore").empty(); }, 3000); } }); });
頁面:
<ul class="art-list"> {loop $art_all $k $v} <li><a href="#">{$v[‘title‘]}</a></li> {/loop}
</ul> <div id="nomore" style="text-align:center;color:gray"></div>
控制器:
$this->ys = pc_base::load_model(‘artarea_model‘); $page=intval($_GET[‘pageNum‘])?intval($_GET[‘pageNum‘]):1; //當前頁 $res=$this->ys->select(‘‘,"id"); $total=count($res); //文章總數 $pageSize =3; //每頁顯示條數 $starpage=($page-1)*$pageSize;//起始資料 $totalPage =ceil($total/$pageSize); //總頁數 $sql="select a.*,b.pic_more from v9_artarea a left join v9_artarea_data b on a.id=b.id order by a.inputtime desc limit $starpage,$pageSize "; $art_obj=$this->ys->query($sql); foreach ($art_obj as$k=> $v){ $v[‘pic_more‘]=string2array($v[‘pic_more‘]); $art_all[]=$v; //藝術圈文章列表 }
more
public function art_more(){ $this->ys = pc_base::load_model(‘artarea_model‘); $page=intval($_GET[‘pageNum‘]); $res=$this->ys->select(‘‘,"id"); $total=count($res); //文章總數 $pageSize =3; //每頁顯示條數 $starpage=($page-1)*$pageSize;//起始資料 $totalPage =ceil($total/$pageSize); //總頁數 // if($page>$totalPage){// return json_encode(‘error‘);// }else{ $sql="select a.*,b.pic_more from v9_artarea a left join v9_artarea_data b on a.id=b.id order by a.inputtime desc limit $starpage,$pageSize "; $art_obj=$this->ys->query($sql); foreach ($art_obj as$k=> $v){ $v[‘pic_more‘]=string2array($v[‘pic_more‘]); $art_all[]=$v; //藝術圈文章列表 } echo json_encode($art_all);// } }
jquery 上滑載入更多