|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于PHP的语法结构,刚开始真的很不习惯,真搞不懂为什么每个变量之前都要加个“$”符号,每个语句写完之后都必须加上“分号”来表示此句已经结束,还有,PHP对字母的大小写是敏感的,写的时候一定要注意大小写的区别。上面是我本人的分页类,可得当的修正[php]<?php/***@namePagersclass*@authorRefer*@copyrightwww.phpcq.com*@versionAlpha1.0*@todo下拉菜单分页---From表单传值...能够依据本人的情形(接纳GET传值)**/classPager{/***startRow**@varInt*/public$startRow;/***页面的总数**@varInt*/public$pageTotal;/***翻页值**@varInt*/public$offset;/***每页所显现纪录数**@varInt*/public$pageSize;/***get参数**@varInt*/public$get;/***post参数**@varInt*/public$post;/***机关函数--初始化翻页类(PS:^_^不错的php开辟进修交换群:256271784,考证:gole,有乐趣的话能够到场出去一同会商)**@paramInt$total*@paramInt$pageSize*/publicfunction__construct($total,$pageSize){$this->get=(int)$_GET[startRow];$this->post=(int)$_POST[pageNums];$this->pageSize=$pageSize;$this->pageTotal=ceil($total/$pageSize);switch($_GET[method]){default:$this->startRow=1;$this->offset=0;break;casefirst:$this->first();break;caseprevious:$this->previous();break;casenext:$this->next();break;caselast:$this->last();break;}}/***首页办法**/publicfunctionfirst(){$this->startRow=1;$this->offset=($this->startRow-1)*$this->pageSize;}/***上一页办法**/publicfunctionprevious(){$this->startRow=$this->get-1;if($this->startRow<1){$this->startRow=1;}$this->offset=($this->startRow-1)*$this->pageSize;}/***下一页办法**/publicfunctionnext(){$this->startRow=$this->get+1;if($this->startRow>$this->pageTotal){$this->startRow=$this->pageTotal;}$this->offset=($this->startRow-1)*$this->pageSize;}/***最初页办法**/publicfunctionlast(){$this->startRow=$this->pageTotal;$this->offset=($this->startRow-1)*$this->pageSize;}/***下拉菜单翻页**@returnInt*/publicfunctionnumPages(){if($this->post){$pageNums="<option>$this->post</option>";$this->startRow=$this->post;$this->offset=($this->post-1)*$this->pageSize;}for($i=1;$i<=$this->pageTotal;$i++){if($i!=$this->post){$pageNums.="<option>$i</option>";}}return$pageNums;}/***以后是第几页**@returnInt*/publicfunctionnoncePage(){if($this->post){return$this->startRow=$this->post;}else{return$this->startRow=$this->startRow;}}}挪用办法:[php]$total=$total->total();//总纪录$pageSize=15;//每页显现的纪录$pager=newPager($total,$pageSize);if($pager->post){$startRow=$pager->noncePage();}$startRow=$pager->startRow;$pager->numPages();$article->query("SELECT*FROM`categories`asc,`articles`asnWHEREc.id=n.pidORDERBYn.idDESCLIMIT$pager->offset,$pageSize");while($article->fetchArray()){$article->data[content]=mb_substr(strip_tags($article->data[content]),0,40,utf-8);$articleIndex[]=$article->data;}$article->free();}else{header("location:?act=login");}$view->view->assign(startRow,$startRow);//caption$view->view->assign(total,$total);//caption$view->view->assign(pageNums,$pager->numPages());//pageNums$view->view->assign(noncePage,$pager->noncePage());//pageNums$view->view->assign(pageTotal,$pager->pageTotal);//pageTotal模板页面:[php]<!--{if$pageTotal>1}--><formaction=""method="post"><divid="projectpages"class="fontpage">Pager:<selectname="pageNums"onchange="javascript:submit();"style="height:20px;"><!--{$numPages}--></select><ahref="?act=blog&method=first&startRow=<!--{$startRow}-->">First</a><ahref="?act=blog&method=previous&startRow=<!--{$startRow}-->">Previous</a><ahref="?act=blog&method=next&startRow=<!--{$startRow}-->">Next</a><ahref="?act=blog&method=last&startRow=<!--{$startRow}-->">Last</a></div></form><!--{/if}-->可以说你的马步已经扎的差不多了,接下来就要开始练把势的时候了,如果有条件的话,用笔或者打印一个简易的PHP手册在身上,时不时的摸出来看看,记得,去WC也不能放过(^2^)。 |
|