www.gusucode.com > 仿51.com的php源码 1.1 > include/page.php
<?php /** * 翻页程序的类 调用方法 * $gopage = new GoPage(总页数,总记录数) 要和dbConn->getGopageRs($sql)配合使用 * 调用显示模式 $gopage->style();允许为空。默认为样式0,可以填写0-2,出现不同模式 */ Class GoPage{ var $tpages;//总页数 var $tcounts;//总记录数 var $page; var $deferentparameter; var $selfvariable; function Gopage($tpages,$tcounts){ global $page; global $deferentparameter; global $selfvariable; $page=$_REQUEST["page"]; $this->tpages = $tpages; $this->tcounts = $tcounts; if($page==0 || $page==""){ $this->page = 1; }else{ $this->page = $page; } if($page > $this->tpages){ $this->page = $this->tpages; } $this->deferentparameter = $deferentparameter; $this->selfvariable = $selfvariable; } function style($slectflag=""){ switch($slectflag){ case "0": $this->style0(); break; case "1": $this->style1(); break; case "2": $this->style2(); break; case "3":$this->style3(); break; case "4":$this->style4(); break; default: $this->style0(); } } function style0(){ $fontcolor = "#CB5C0B"; ?> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="infoTable"> <tr> <td align="center" valign="bottom"> 共<b><font color="<?=$fontcolor?>"><?=$this->tcounts?></font></b>条记录 </td> <td align="center" valign="bottom"> 第<b><font color="<?=$fontcolor?>"><?=$this->page?></font></b>页/ 共<b><font color="<?=$fontcolor?>"><?=$this->tpages?></font></b>页 </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=1<?=$this->deferentparameter.$this->selfvariable?>">第一页</a> <?}else{?> 第一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page-1?><?=$this->deferentparameter.$this->selfvariable?>">上一页</a> <?}else{?> 上一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page+1?><?=$this->deferentparameter.$this->selfvariable?>">下一页</a> <?}else{?> 下一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->tpages?><?=$this->deferentparameter.$this->selfvariable?>">末一页</a> <?}else{?> 末一页 <?}?> </td> <td align="center" valign="bottom"> <select name="selectpage" onChange="location.href=this.value;" style="font-size:9pt;height:18px;font-family:'宋体'"> <? for($pagei=0;$pagei<$this->tpages;$pagei++){ if($pagei+1==$this->page){ $tempselect = "selected"; }else{ $tempselect = ""; } ?> <option value="<?=$PHP_SELF?>?page=<?=$pagei+1?><?=$this->deferentparameter.$this->selfvariable?>" <?=$tempselect?>>去<?=$pagei+1?>页</option> <?}?> </select> </td> </tr> </table> <? } function style1(){ $fontcolor = "#CB5C0B"; $gobtnnameadd = $gobtnnameadd+1; ?> <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="infoTable"> <tr> <td align="center" valign="bottom"> 共<b><font color="<?=$fontcolor?>"><?=$this->tcounts?></font></b>条记录 </td> <td align="center" valign="bottom"> 第<b><font color="<?=$fontcolor?>"><?=$this->page?></font></b>页/ 共<b><font color="<?=$fontcolor?>"><?=$this->tpages?></font></b>页 </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=1<?=$this->deferentparameter.$this->selfvariable?>">第一页</a> <?}else{?> 第一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page-1?><?=$this->deferentparameter.$this->selfvariable?>">上一页</a> <?}else{?> 上一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page+1?><?=$this->deferentparameter.$this->selfvariable?>">下一页</a> <?}else{?> 下一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->tpages?><?=$this->deferentparameter.$this->selfvariable?>">末一页</a> <?}else{?> 末一页 <?}?> </td> <td align="center" valign="bottom"> 去 <input type="text" name="selectpagetext<?=$gobtnnameadd?>" value="<?=$this->page?>" maxlength="<?=strlen($this->tpages)?>" style="width:<?=strlen($this->tpages)*10?>px;font-size:9pt;height:18px;font-family:'宋体'" onMouseOver="this.focus()" onFocus="this.select()" dir="rtl"> 页 <button style="font-size:9pt;font-family:'宋体'" type="button" name="GoBtn" onClick=" if(((window.document.all('selectpagetext<?=$gobtnnameadd?>').value < <?=$this->page?> && window.document.all('selectpagetext<?=$gobtnnameadd?>').value >=1) || (window.document.all('selectpagetext<?=$gobtnnameadd?>').value > <?=$this->page?> && window.document.all('selectpagetext<?=$gobtnnameadd?>').value <=<?=$this->tpages?>) && !isNaN(window.document.all('selectpagetext<?=$gobtnnameadd?>').value))){ location.replace('<?=$PHP_SELF?>?page='+ window.document.all('selectpagetext<?=$gobtnnameadd?>').value+ '<?=$this->deferentparameter.$this->selfvariable?>'); }"><img src="../images/button/go.gif"></button> </td> </tr> </table> <? } function style2(){ $fontcolor = "#CB5C0B"; ?> <table border="0" align="center" cellpadding="0" cellspacing="0" class="infoTable"> <tr> <td align="center" valign="bottom"> 共<b><font color="<?=$fontcolor?>"> <?=$this->tcounts?> </font></b>条记录 </td> <td align="center" valign="bottom"> 第<b><font color="<?=$fontcolor?>"> <?=$this->page?> </font></b>页/ 共<b><font color="<?=$fontcolor?>"> <?=$this->tpages?> </font></b>页 </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=1<?=$this->deferentparameter.$this->selfvariable?>">第一页</a> <?}else{?> 第一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page>1){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page-1?><?=$this->deferentparameter.$this->selfvariable?>">上一页</a> <?}else{?> 上一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page+1?><?=$this->deferentparameter.$this->selfvariable?>">下一页</a> <?}else{?> 下一页 <?}?> </td> <td align="center" valign="bottom"> <?if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->tpages?><?=$this->deferentparameter.$this->selfvariable?>">末一页</a> <?}else{?> 末一页 <?}?> </td> </tr> </table> <? } function style3(){ $x=5; ?> <div class="fenye"> <?=$this->tcounts?> 条记录 <?=$this->page?> / <?=$this->tpages?>页 <?if($this->page>5){?><a href="<?=$PHP_SELF?>?page=1<?=$this->deferentparameter.$this->selfvariable?>">第一页</a><?}?> <?if($this->page>1){?><a href="<?=$PHP_SELF?>?page=<?=$this->page-1?><?=$this->deferentparameter.$this->selfvariable?>">上一页</a> <?php }?> <?php $page2=(int)((int)$this->page/$x); if(($this->page/$x)>$page2) { $page2=$page2+1; } $k=$page2 * $x; if($k>$this->tpages) { $k=$this->tpages; } ?> <?php for ($i=$page2 * $x-($x-1);$i<=$k;$i++){?><?php if($i<>$this->page){?> <span><a href="<?=$PHP_SELF?>?page=<?=$i?><?=$this->deferentparameter.$this->selfvariable?>"><?=$i?></a></span><?php }else{?> <span class="this-page"><?=$this->page?></span><?php }}?> <?php if($this->page<$this->tpages){?> <a href="<?=$PHP_SELF?>?page=<?=$this->page+1?><?=$this->deferentparameter.$this->selfvariable?>">下一页</a><?php }?> <?php if((($this->page)+5)<$this->tpages){?><a href="<?=$PHP_SELF?>?page=<?=$this->tpages?><?=$this->deferentparameter.$this->selfvariable?>">末一页</a><?}?> </div> <?php } function style4() {?> <div class="fenye1">共有<?=$this->tcounts?>记录 <?php for($i=1;$i<=$this->tpages;$i++){?> <?php if($this->page==$i){?> <span class="this-page"><?php echo $i; ?></samp><?php }else{?> <samp><a href="<?=$PHP_SELF?>?page=<?=$this->page+1?><?=$this->deferentparameter.$this->selfvariable?>"><?php echo $i; ?></a></samp> <?php }}?> </div> <?php } } ?>