/
www
/
wwwroot
/
guandn.cn
/
inc
/
Upload File
HOME
<?php if (!defined('BY')) { exit('Access Denied'); } class apibase { public $jsondata; public $db; public $root; public $conf; public function __construct() { $this->jsondata = $GLOBALS['jsondata']; $this->db = $GLOBALS['db']; $this->root = $GLOBALS['root']; $this->root = $GLOBALS['conf']; } public function index() { json($this->jsondata); } protected function pgdata($sql = "", $num = 10, $pgmode = false, $orderby = "", $where = "", $countsql = "", $pnshow = false) { //$sql: 数据SQL //$num: 显示数据条数,分页模式时自动设置为每页显示条数 //$pgmode: 数据模式:false:默认无分页模式,true:分页模式 //$pn: 当前页大于总页数,是否显示最后一页数据 if ($pgmode) { $datacount = 0; if (empty($countsql)) { $datacount = $this->db->getrsnum("{$sql} {$where} {$orderby}"); } else { $datacount = $this->db->getrsnumbycount("{$countsql} {$where} {$orderby}"); } $curpage = intval(strget("p")); if ($curpage <= 0) { $curpage = 1; } $prepage = $curpage - 1; $nextpage = $curpage + 1; $totalpage = ceil($datacount / $num); if ($prepage <= 0) { $prepage = -1; } if ($nextpage > $totalpage) { $nextpage = -1; } if ($curpage > $totalpage) { $prepage = $totalpage - 1; if ($pnshow) { $curpage = $totalpage; $this->jsondata['datacount'] = $datacount; } } $this->jsondata['curpage'] = $curpage; $this->jsondata['prepage'] = $prepage; $this->jsondata['nextpage'] = $nextpage; $this->jsondata['totalpage'] = $totalpage; $this->jsondata['datacount'] = $datacount; $start = $num * ($curpage - 1); $sql = "{$sql} {$where} {$orderby} limit {$start}, {$num}"; $data = $this->db->getall($sql); if ($data) { $this->jsondata['status'] = 'ok'; $this->jsondata['data'] = $data; } else { $this->jsondata['data'] = array(); } } else { $data = $this->db->getall("{$sql} {$where} {$orderby}"); if ($data) { $this->jsondata['status'] = 'ok'; $this->jsondata['okmsg'] = '加载完毕'; $this->jsondata['datacount'] = count($data); $this->jsondata['data'] = $data; } else { $this->jsondata['errormsg'] = '没有找到数据'; } } return $this->jsondata; } }