<span class="unnamed3"><!--二泉.net --><br><br>class Pages{<br> var $cn; //连接数据库游标<br> var $d; //连接数据表的游标<br> var $result; //结果<br> var $dsn; //dsn源<br> var $user; //用户名 <br> var $pass; //密码<br> <br> var $total; //记录总数<br> var $pages; //总页数<br> var $onepage; //每页条数<br> var $page; //当前页<br> var $fre; //上一页<br> var $net; //下一页<br> var $i; //控制每页显示<br><br> function getConnect($dsn,$user,$pass){<br> $this->cn=@odbc_connect($dsn,$user,$pass);<br> if(!$this->cn){<br> $error="连接数据库出错";<br> $this->getMess($error);<br> } <br> }<br> <br> function getDo($sql){//从表中查询数据<br> $this->d=@odbc_do($this->cn,$sql);<br> if(!$this->d){<br> $error="查询时发生了小错误......";<br> $this->getMess($error);<br> }<br> return $this->d;<br> }<br><br> function getTotal($sql){<br> $this->sql=$sql;<br> $dT=$this->getDo($this->sql); //求总数的游标<br> $this->total=odbc_result($dT,'total');//这里为何不能$this->d呢?<br> return $this->total; <br> }<br><br> function getList($sql,$onepage,$page){<br> $this->s=$sql;<br> $this->onepage=$onepage;<br> $this->page=$page;<br> $this->dList=$this->getDo($this->s); //连接表的游标<br> $this->pages=ceil($this->total/$this->onepage);<br> if($this->pages==0) <br> $this->pages++; //不能取到第0页<br> if(!isset($this->page)) <br> $this->page=1;<br> $this->fre = $this->page-1; //将显示的页数<br> $this->nxt = $this->page+1; <br> $this->nums=($this->page-1)*$this->onepage; <br> //if($this->nums!=0){<br> // for($this->i=0;$this->igetNums();odbc_fetch_row($this->dd),$this->i++);//同上<br> //}<br> //$this->i=0;//为何这部分不能封装?<br> return $this->dList; <br> }<br><br> function getFanye(){<br> $str="";<br> if($this->page!=1)<br> $str.="<a href=".%24PHP_SELF."> 首页 </a><a href=".%24PHP_SELF.">fre."> 前页 </a>";<br> else<br> $str.="<font color="999999">首页 前页</font>";<br> if($this->pagepages)<br> $str.="<a href=".%24PHP_SELF.">nxt."> 后页 </a>";<br> else<br> $str.="<font color="999999"> 后页 </font>";<br> if($this->page!=$this->pages)<br> $str.="<a href=".%24PHP_SELF.">pages."> 尾页 </a>";<br> else<br> $str.="<font color="999999"> 尾页 </font>";<br> <br> $str.="共".$this->pages."页";<br> $str.="您正浏览第<font color="red">".$this->page."</font>页";<br> return $str;<br> }<br> <br> function getNums(){<br> return $this->nums;<br> }<br> <br> function getOnepage(){//每页实际条数<br> return $this->onepage;<br> }<br><br> function getI(){<br> return $this->i;<br> }<br> <br> function getPage(){<br> return $this->page;<br> }<br><br> function getMess($error){//定制消息<br> echo"<center>$error</center>";<br> exit;<br> }<br>}<br><br>$pg=new Pages();<br>$pg->getConnect("lei","sa","star");<br>$pg->getTotal("select count(*) as total from xs"); //连学生表求总数<br>$pg->getList("select xs_name from xs order by xs_id",8,$page); <br>if($pg->getNums()!=0){<br> for($i=0;$igetNums();odbc_fetch_row($pg->dList),$i++);//同上<br>}<br>$i=0;<br>while(odbc_fetch_row($pg->dList)){<br> $name=odbc_result($pg->dList,"xs_name");<br> echo $name."<br>";<br> if($i==$pg->getOnepage()){//跳出循环<br> break;<br> }<br> $i++;<br>}<br>echo$pg->getFanye();<br>?><br><br></span> <p style="width:100%;text-align:center;margin:10px 0"> <br> <br> </p> <p style="width:100%;text-align:center;margin:10px 0"> </p> <p class="clear"></p>