如何用php实现从数据库表中查询?(初学者) php中文完全手册里有。到处都有下的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是要分页的类吗〉???有一个<?php /********************************************* TViewPage v 1.0 分页显示Mysql数据库记录的类 作者:sharetop E-mail:[email protected] 时间:2000-8-31 本类没有提供连接数据库的功能,所以需在外部打开相应的数据库。 本类也没有提供显示记录的功能,只是分页读取记录至 Result二维数组中。 需在外部自定义数据显示格式。 ***********************************************/ class TViewPage { var $Table; //表名 var $MaxLine; //每页显示行数 var $Offset; //记录偏移量 var $Total; //记录总数 var $Number; //本页读取的记录数 var $Result; //读出的结果 var $TPages; //总页数 var $CPages; //当前页数 var $Condition; //显示条件 如:where id='$id' order by id desc var $PageQuery; //分页显示要传递的参数 //******构造函数************* //参数:表名、最大行数、偏移量 function TViewPage($TB,$ML,$OF=0){ $this->Table=$TB; $this->MaxLine=$ML; $this->Offset=$OF; } //********设置显示条件********* //如:where id='$id' order by id desc //要求是字串,符合SQL语法(本字串将加在SQL语句后) function SetCondition($s){ $this->Condition=$s; } //******设置传递参数************ // key参数名 value参数值 // 如:setpagequery("id",$id);如有多个参数要传递,可多次调用本函数。 function SetPageQuery($key,$value){ $tmp[key]=$key; $tmp[value]=$value; $this->PageQuery[]=$tmp; } //********读取记录*************** // 主要工作函数,根据所给的条件从表中读取相应的记录 // 返回值是一个二维数组,Result[记录号][字段名] function ReadList() { $SQL="SELECT Count(*) AS total FROM ".$this->Table." ".$this->Condition; $result=mysql_query($SQL) or die(mysql_error()); $row=mysql_fetch_Array($result); $this->Total=$row[total]; if($this->Total>0) { //根据条件 Condition $SQL="SELECT * FROM ".$this->Table." ".$this->Condition. " LIMIT ".$this->Offset." , ".$this->MaxLine; $result=mysql_query($SQL) or die(mysql_error()); $this->Number=mysql_num_rows($result); while($row=mysql_fetch_Array($result)) $this->Result[]=$row; } return $this->Result; } //**********显示页数************* //显示当前页及总页数 function ThePage() { $this->TPages=ceil($this->Total/$this->MaxLine); $this->CPages=$this->Offset/$this->MaxLine+1; echo "第".$this->CPages."页/共".$this->TPages."页"; } //**********显示翻页按钮************* //此函数要在ThePage()函数之后调用!!! //显示首页、下页、上页、未页,并加上要传递的参数 function Page() { $first=0; $next=$this->Offset+$this->MaxLine; $prev=$this->Offset-$this->MaxLine; $last=($this->TPages-1)*$this->MaxLine; $k=count($this->PageQuery); $strQuery=""; //生成一个要传递参数字串 for($i=0;$i<$k;$i++){ $strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value]; } if($this->Offset>=$this->MaxLine) echo "<A href=$PHP_SELF?offset=".$first.$strQuery.">首页</A>|"; if($prev>=0) echo "<A href=$PHP_SELF?offset=".$prev.$strQuery.">上一页</A>|"; if($next<$this->Total) echo "<A href=$PHP_SELF?offset=".$next.$strQuery.">下一页</A>|"; if($this->TPages!=0 && $this->CPages<$this->TPages) echo "<A href=$PHP_SELF?offset=".$last.$strQuery.">末页</A>"; } //******end class } ?> php中如何屏蔽非法字符 PHP伪静态新手 php代码,截取页面并过滤 关于Form enctype="multipart/form-data" WAMP5 1.6.1 问题 使用FCKeditor时遇到的问题 注册用户分行显示问题,急!! 关于SRPBoard社区的模块化设计的问题(100分) 怎样才能同时删除多条记录。请帮助。我在线等待。 做过activeX的同志们看过来!!!!!!!! php与sql server2000数据库时间字段的问题 老菜问题就是多,这个如何解决。。。。
有一个
<?php
/*********************************************
TViewPage v 1.0 分页显示Mysql数据库记录的类 作者:sharetop
E-mail:[email protected]
时间:2000-8-31 本类没有提供连接数据库的功能,所以需在外部打开相应的数据库。
本类也没有提供显示记录的功能,只是分页读取记录至 Result二维数组中。
需在外部自定义数据显示格式。
***********************************************/
class TViewPage { var $Table; //表名
var $MaxLine; //每页显示行数
var $Offset; //记录偏移量
var $Total; //记录总数
var $Number; //本页读取的记录数
var $Result; //读出的结果
var $TPages; //总页数
var $CPages; //当前页数
var $Condition; //显示条件 如:where id='$id' order by id desc
var $PageQuery; //分页显示要传递的参数
//******构造函数*************
//参数:表名、最大行数、偏移量
function TViewPage($TB,$ML,$OF=0){
$this->Table=$TB;
$this->MaxLine=$ML;
$this->Offset=$OF;
}
//********设置显示条件*********
//如:where id='$id' order by id desc
//要求是字串,符合SQL语法(本字串将加在SQL语句后)
function SetCondition($s){
$this->Condition=$s;
} //******设置传递参数************
// key参数名 value参数值
// 如:setpagequery("id",$id);如有多个参数要传递,可多次调用本函数。
function SetPageQuery($key,$value){
$tmp[key]=$key; $tmp[value]=$value;
$this->PageQuery[]=$tmp;
}
//********读取记录***************
// 主要工作函数,根据所给的条件从表中读取相应的记录
// 返回值是一个二维数组,Result[记录号][字段名]
function ReadList() {
$SQL="SELECT Count(*) AS total FROM ".$this->Table." ".$this->Condition;
$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$this->Total=$row[total];
if($this->Total>0) { //根据条件 Condition
$SQL="SELECT * FROM ".$this->Table." ".$this->Condition.
" LIMIT ".$this->Offset." , ".$this->MaxLine; $result=mysql_query($SQL) or die(mysql_error());
$this->Number=mysql_num_rows($result); while($row=mysql_fetch_Array($result)) $this->Result[]=$row;
}
return $this->Result;
}
//**********显示页数*************
//显示当前页及总页数
function ThePage() {
$this->TPages=ceil($this->Total/$this->MaxLine);
$this->CPages=$this->Offset/$this->MaxLine+1;
echo "第".$this->CPages."页/共".$this->TPages."页";
} //**********显示翻页按钮*************
//此函数要在ThePage()函数之后调用!!!
//显示首页、下页、上页、未页,并加上要传递的参数
function Page() {
$first=0;
$next=$this->Offset+$this->MaxLine;
$prev=$this->Offset-$this->MaxLine;
$last=($this->TPages-1)*$this->MaxLine; $k=count($this->PageQuery);
$strQuery=""; //生成一个要传递参数字串
for($i=0;$i<$k;$i++){
$strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value];
} if($this->Offset>=$this->MaxLine)
echo "<A href=$PHP_SELF?offset=".$first.$strQuery.">首页</A>|";
if($prev>=0)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery.">上一页</A>|";
if($next<$this->Total)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery.">下一页</A>|";
if($this->TPages!=0 && $this->CPages<$this->TPages)
echo "<A href=$PHP_SELF?offset=".$last.$strQuery.">末页</A>";
}
//******end class
} ?>