get_table_count ( $table, $condition ); $total = intval ( $total_count / $page_size ); $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1; $page ['total_data'] = $total_count; $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1; $i = 1; $page_max = 1; if ($on_page > 10) { $page_max = intval ( $on_page / 10 ) + 1; $i = intval ( $on_page / 10 ) * 10 - 1; } for(; $i <= $page ['total_page']; $i ++) { if ($i == $on_page) { if ($other == "page") $page_c .= '' . $i . ''; else $page_c .= ' ' . $i . ' '; } else if ($other == "page") $page_c .= '' . $i . ''; else $page_c .= ' ' . $i . ' '; if ($i == (10 * $page_max)) break; } $page ['page'] = $page_c; $page ['lower'] = (-- $on_page) * $page_size; return $page; } /** * 获取总页数 * @param unknown_type $table * @param unknown_type $condition */ public function get_table_count($table = "", $condition = "") { $sql = "select count(*) as count from " . $table . " where 1 " . $condition; $query = $this->db()->query ( $sql ); $result = $query->fetch (); return $result ['count']; } /** * 获取数据 * @param unknown_type $data 一般选择条件 * @param unknown_type $limit * @param unknown_type $condition * @param unknown_type $table */ function get_list($data = array(), $condition = "", $limit = "", $table = "") { foreach ( $data as $key => $value ) { if (is_numeric ( $value )) $condition .= " and " . $key . " = " . $value; else $condition .= " and " . $key . " like '%" . $value . "%' "; } $condition = ' where 1 ' . $condition . $limit; $sql = "select * from " . $table . $condition; $query = Doo::db ()->query ( $sql ); $result = $query->fetchAll (); return $result; } /** * 批量更新数据 * @param unknown_type $params 一个字段为一个数组 * @param unknown_type $table * @param unknown_type $id */ function update_list($params = array(), $table = "", $id = "") { $pa = array (); $co = array (); $wh = array (); $count = count ( $params [$id] ); foreach ( $params as $key => $value ) { array_push ( $pa, $key ); if ($key != $id) { array_push ( $wh, $key . "=VALUES(" . $key . ")" ); } } //获取更新内容 for($i = 0; $i < $count; $i ++) { $tm = array (); foreach ( $pa as $k ) { array_push ( $tm, "'" . $params [$k] [$i] . "'" ); } $tm = implode ( ",", $tm ); array_push ( $co, "(" . $tm . ")" ); } $pa = implode ( ",", $pa ); $wh = implode ( ",", $wh ); $co = implode ( ",", $co ); $sql = "INSERT INTO " . $table . " (" . $pa . ") VALUES " . $co . " ON DUPLICATE KEY UPDATE " . $wh; $query = Doo::db ()->query ( $sql ); } /** * 获取通行证用户信息 * @param unknown_type $username */ function get_sso_user_info_by_name($username = "") { require_once (SITE_PATH . '/protected/plugin/client.php'); $client = new client ( ZHSSO ); $userinfo = $client->zhsso_getUserbyName ( $username ); $userinfo = explode ( "\r", $userinfo ); $ts = json_decode ( $userinfo ['1'], true ); return $ts; } } ?>