- 论坛徽章:
- 0
|
本类是把数组中的数据分页显示出来,
如要显示数据库中的数据,先把数据库中的数据倒入数组。
本人学php才几个月,请大家多批评一下。
下面是分页类和把数据库中数据倒入数组的类源码。
分页类:
$forStartCtrl 和 $forEndCtrl 两个变量是在显示数据时用来控制for循环.
把MySQL数据库数据倒入数组类,如用别的数据库,请修改相关代码。
- <?php
- /***************************************************
- [UPLINK_SKY] mysql.class.php --Meng LinuxRuby.
- This is the freeware.
- Author : Meng LinuxRuby (sleep_linux@163.com).
- CopyRight: (C)2004.05.* Meng LinuxRuby.
- ***************************************************/
- class mysqlDB {
- private $sqlResult = array();
- private $sqlLink;
- function __construct($dbHost, $dbUser, $dbPass, $dbBase){
- try{
- $this->;sqlLink = MYSQL_CONNECT($dbHost, $dbUser, $dbPass);
- MYSQL_SELECT_DB($dbBase);
- }catch(Exception $exception){
- print "Can't Connect to MySQL Database";
- print $exception->;getMessage();
- }
- }
- function fetchArray($sqlString){
- try{
- if ($Rs = MYSQL_QUERY($sqlString, $this->;sqlLink)){
- while ($result = MYSQL_FETCH_ARRAY($Rs)){
- $this->;sqlResult[] = $result;
- }
- return $this->;sqlResult;
- }else{
- return false;
- }
- }catch(Exception $exception){
- print $exception->;getMessage();
- }
- }
- function __destruct(){
- try{
- return MYSQL_CLOSE($this->;sqlLink) ? TRUE:FALSE;
- }catch(Exception $exception){
- print $exception->;getMessage();
- }
- }
- }
- ?>;
复制代码
使用范例:
- $page = new Page($dataArray);
- for ($i=$page->;getStartCtrl();$i<$page->;getEndCtrl();$i++){
- //显示数据
- echo "<br>;".$dataArray[$i]['User_ID'];
- echo "<br>;".$dataArray[$i]['User_Pass'];
- echo "<br>;".$dataArray[$i]['User_Auth'];
- }
- //页标
- print $page->;showPageTag();
复制代码 |
|