php编写数据库操作:查询列表并分页
### $db->get_list方法的使用
1.首先加载对应的数据库类
`$db = load_class('db');`
2.调用get_list方法
`$result = get_list($table, $where = '', $field = '*', $startid = 0, $pagesize = 200,$page = 0, $order = '', $group = '', $keyfield = '', $urlrule = '',$array = array(),$colspan = 10);`
3.分页的调用
`{$pages}`
***************************************************************
#### 文件:coreframe/app/link/admin/index.php
```php
// +----------------------------------------------------------------------
defined('IN_WZ') or exit('No direct script access allowed');
/**
* 友情链接
*/
load_class('admin');
class index extends WUZHI_admin {
private $db;
function __construct() {
$this->db = load_class('db');
}
/**
* 友情链接列表
*/
public function listing() {
$page = isset($GLOBALS['page']) ? intval($GLOBALS['page']) : 1;
$page = max($page,1);
$result = $this->db->get_list('link', '', '*', 0, 20,$page,'sort ASC');
$pages = $this->db->pages;
$total = $this->db->number;
include $this->template('listing');
}
}
```
***************************************************************
- $table 数据表名
- array|string $where 条件 ,数组或者字符串 .如:array('id'=>1,'cid'=>1) 或 `id`=1 AND `cid`=1
- string $field 要查询的字段
- int $startid 开始索引,如果是从第二条开始,那么则为1,mysql从0开始索引
- int $pagesize 每页显示数量,如果不分页,则显示为总数
- int $page 当前页
- string $order 排序
- string $group mysql group by 属性
- string $keyfield 以某字段名为结果索引
- string $urlrule url规则
- array $array url规则中的参数名和参数值,二维数组
- int $colspan 分页显示总列数