热搜:NVER node 开发 php

大神帮我看下,我的查询分页类哪里错了分页类

2024-09-06 17:05:01
大神帮我看下,我的查询分页类哪里错了分页类

这是page.class.php<?phpclass DividePage{//分页类	private $total;//要显示的总记录数	private $url;//请求的URL地址	private $displaypg;//每页显示的记录数,默认为每页显示10条记录	private $page;//当前页码	private $lastpg;//总页数,即最后一页的页码	private $prepg;//前一页	private $nextpg;//后一页	private $firstcount;//记录条数开始的序号从0开始	private $startd;//记录条数开始的记录号.	private $stopd;//记录条数结束的记录号.//构造函数public function __construct($url, $total, $displaypg){	$this->url = $url;//请求的URL	$this->total = $total;//总记录数	//if($displaypg == '')	$this->displaypg = $displaypg;//每页显示的记录数	$this->initDividePage();//初始化分页类	//echo ','.$this->displaypg;}//初始化分页类private function initDividePage(){	//分析URL	$parse_url = parse_url($this->url);//将URL解释为有固定键值对的数组	$url_query = $parse_url['query'];//取出URL中的查询字符串	if($url_query){//如果有查询字符串,则删除查询字串中当前页的查询字段如:&page=$page或page=$page		ereg('(^|&)page=([0-9]*)', $url_query, $k);		$this->page = $k[2];//取得当前页的值		$url_query = ereg_replace("(^|&)page=$this->page", '', $url_query);//删除查询字串中当前页的查询字段如:&page=$page或page=$page		$this->url = str_replace($parse_url['query'], $url_query, $this->url);//保留其他的查询字串,		$this->page = $this->page ? $this->page : 1;//如果查询字符串中没有当前页的值就设当前页为1		if($url_query){//如果有其他查询字符串,则以&page=$page形式添加翻页查询字串			$this->url .= '&page';		}else{//如果没有其他查询字串,则以page=$page形式添加翻页查询字串			$this->url .= 'page';		}	}else{//如果没有查询字串,则在URL后添加?page=$page形式的翻页查询字串		$this->page = 1;		$this->url .= '?page';	}	$this->lastpg = ceil($this->total / $this->displaypg);//计算总页数,即最后一页的页码    $this->page = min($this->lastpg, $this->page);//如果当前页大于总页数,则当前页为最后一页的页码    $this->prepg = $this->page - 1;//上一页为当前页减一    $this->nextpg = $this->page + 1;//(($this->page == $this->lastpg) ? $this->lastpg : ($this->page + 1));//下一页为当前页加一,如果当前页为最后一页,则下一页为0    $this->firstcount = ($this->page - 1) * $this->displaypg;//计算当前页,记录条数开始的记录号,从0开始.	$this->startd = $this->total ? ($this->firstcount + 1) : 0;//记录开始号从1开始	$this->stopd = min($this->firstcount + $this->displaypg, $this->total);//记录结束号	//echo $this->displaypg;	//echo $this->nextpg.'+=+='.$this->lastpg;}public function getPageInfo(){//取得当前页面的基本信息,如:显示第 1-10 条记录,共 23 条记录。	return '显示第'.$this->startd.'-'.$this->stopd.'条记录,共'.$this->total.'条记录。';}public function getCommonPageNav(){//取得通常的分页导航,如:首页 上一页 下一页 尾页	$commonnav = '';	if($this->lastpg == 1){//如果只有一页,则返回翻页导航,退出,不显示下一页,上一页等。。。		return $commonnav;		break;	}	$commonnav = 'url.'=1" class="compagestyle">首页';//设置首页导航,page=1	if($this->prepg){		$commonnav .= 'url.'='.$this->prepg.'" class="compagestyle">上一页';	}else{		$commonnav .= '上一页';	}	if($this->nextpg <= $this->lastpg){		$commonnav .= 'url.'='.$this->nextpg.'" class="compagestyle">下一页';	}else{		$commonnav .= '下一页';	}	$commonnav .= 'url.'='.$this->lastpg.'" class="compagestyle">尾页';//显示尾页链接	return $commonnav;}//取得跳转分页导航,如:第n页public function getJumpPageNav(){	//url.'="+this.value\'>'."\n";	for($i = 1; $i <= $this->lastpg; $i++){		if($i == $this->page){//把当前页的页码作为默认选项			$jumpnav .= ''."\n";		}else{			$jumpnav .= ''."\n";		}	}	$jumpnav .= '页,共'.$this->lastpg.'页';	return $jumpnav;}//取得所有的分页导航public function getAllPageNav(){	$temp =  $this->getPageInfo().$this->getCommonPageNav().$this->getJumpPageNav();	return $temp;}//取得当前页需显示的记录,在数据库中的限定范围,如0-9public function getLimitStr(){	//echo $this->page;	//echo $this->firstcount;		//echo $this->dispalypg;	$temp = $this->firstcount.','.$this->displaypg;	//echo $temp;	return $temp;}}?>这是调用的<?php include 'config.php';include 'page,class.php';//使用实例:$result=mysql_query("SELECT * FROM user");//从数据库中查询所需显示的数据$total=mysql_num_rows($result);//查询到的数据的总条数$pagesize = 5;//每页显示的记录条数$url = $_SERVER['REQUEST_URI'];//请求的URI$dividepageclass = new DividePage($url, $total, $pagesize); //创建分页类,(类能自动初始化)$limitstr = $dividepageclass->getLimitStr();//取得当前页要显示的记录开始序号和每页显示条数,如:0, 5(显示从0开始的5条记录)echo $dividepageclass->getAllPageNav();//显示所有分页导航条,如:显示第11-13条记录,共13条记录。首页 上一页 下一页 尾页 到第 1 页,共 3 页$sql = 'SELECT * FROM user '.$limitstr;$result=mysql_query($sql);//从数据库中取得当前页要显示的记录集,然后显示就OK如:while($row=mysql_fetch_array($result)){echo "
".$row[uid]." | ".$row[pwd];}?>这是数据库配置<?php //这是数据库配置以及参数配置文件$linkkkk=@mysql_connect("localhost","root","");if(!linkkkk){echo "没连接上";}$ss=@mysql_select_db("order");if(!$ss){echo "没找到数据库";}?>


回复讨论(解决方案)

上面的是从网上找的,调用也是按照他说的diaoyong
怎么就不行呢
Parse error: syntax error, unexpected T_WHILE in D:\www\test\fenye.php on line 19

你贴出的代码的第134行
//如:

你贴出的代码的第134行
//如:


不好意思,这个是我的失误 我本地是没有的,重新贴出来

include 'config.php';include 'page.class.php';//使用实例:$result=mysql_query("SELECT * FROM user");//从数据库中查询所需显示的数据$total=mysql_num_rows($result);//查询到的数据的总条数$pagesize = 5;//每页显示的记录条数$url = $_SERVER['REQUEST_URI'];//请求的URI$dividepageclass = new DividePage($url, $total, $pagesize); //创建分页类,(类能自动初始化)$limitstr = $dividepageclass->getLimitStr();//取得当前页要显示的记录开始序号和每页显示条数,如:0, 5(显示从0开始的5条记录)echo $dividepageclass->getAllPageNav();//显示所有分页导航条,如:显示第11-13条记录,共13条记录。首页 上一页 下一页 尾页 到第 1 页,共 3 页$sql = 'SELECT * FROM user '.$limitstr;$result=mysql_query($sql);//从数据库中取得当前页要显示的记录集,然后显示就OKwhile($row=mysql_fetch_array($result))echo "
".$row[uid]." | ".$row[pwd];

你贴出的代码的第134行
//如: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\www\test\fenye.php on line 16

错误信息显示的是 在 fenye.php 第16行发现意外的 while
显然是在16行开始处或之前存在非php语法成分,你自己找找就可以了