$rs = new roster_do($adb,$smarty,$current_user);
$rs->main($do);//入口
class roster_do{
private $db, $tpl, $current_user;
function __construct(&$db,&$tpl,&$current_user){
global $adb,$current_user;
$this->db =& $db;
$this->tpl =& $tpl;
$this->user =& $current_user;
}
public function main($_mod = 'index'){
$mod = "_$_mod";
if(method_exists($this,$mod)) $this->$mod();
}
private function _index(){
$page = $_REQUEST['page'];
if($page=="")$page=1;
if($page<1) $page=1;
$showNumber=10; //每页显示的行数
$sql_num = "SELECT
t1.hp_name
FROM
vtiger_hospital AS t1
LEFT JOIN vtiger_hospitalrel AS t2
ON t1.hp_no = t2.hp_no
WHERE t1.hp_status = '激活'
AND t2.status = '激活'";
$num_res = $this->db->pquery($sql_num,array());
$totalnums = $this->db->num_rows($num_res); //总行数
//如果总数大于每行显示的行数,计算出分页数
if( $totalnums > $showNumber ) {
$totalpage = ceil( $totalnums/$showNumber);
if ($page>$totalpage) $page=1;
$limitbegin = ($page-1)*$showNumber;
$limit=" limit ".$limitbegin.",".$showNumber;
}else{
$totalpage = 1;
}
$sql_hospital = "SELECT
t1.hp_name,
t1.hp_lsubject,
t1.hp_ssubject,
t2.doctor,
t2.time,
t2.surplus_num,
t2.total_num
FROM
vtiger_hospital AS t1
LEFT JOIN vtiger_hospitalrel AS t2
ON t1.hp_no = t2.hp_no
WHERE t1.hp_status = 'A'
AND t2.status = 'A' $limit";
$process_result = $this->db->run_query_allrecords($sql_hospital);
//where条件
if($hp_name != ""){
$where = " AND t1.hp_name like '%".$hp_name."%' ";
}
if($hp_lsubject != ""){
$where = $where." AND t1.hp_lsubject like '%".$hp_lsubject."%' ";
}
if($hp_ssubject != ""){
$where = $where." AND t1.hp_ssubject like '%".$hp_ssubject."%' ";
}
if($doctort != ""){
$where = $where." AND t2.doctort like '%".$doctort."%' ";
}
if($time != ""){
$where = $where." AND t2.time like '%".$time."%' ";
}
$sql_num = "SELECT
t1.hp_name
FROM
vtiger_hospital AS t1
LEFT JOIN vtiger_hospitalrel AS t2
ON t1.hp_no = t2.hp_no
WHERE t1.hp_status = 'A'
AND t2.status = 'A' $where ";
$num_res = $this->db->pquery($sql_num,array());
$totalnums = $this->db->num_rows($num_res); //总行数