/*
* mysql数据库 分页类
* @package pagelist
* @author yytcpt(無影)
* @version 2008-03 -27
* @copyrigth http://www.d5s. cn/
*/
/*
* 分页样式
.page{float: left;font: 11px Arial, Helvetica, sans-serif; パディング:6px 0; マージン: 0px 10%; margin-top: 10px;}
.page a, .page strong{padding: 2px 6px; ボーダー: 実線 1px #ddd; 背景: #fff; text-decoration: none;}
.page a:visited{padding: 2px 6px; ボーダー: 実線 1px #ddd; 背景: #fff; text-decoration: none;}
.page .break{padding: 2px 6px; 境界線: なし。 背景: #fff; text-decoration: none;}
.page strong{padding: 2px 6px; 境界線の色: #999; フォントの太さ: 太字; フォントサイズ: 13px; 垂直配置: 上; 背景: #fff;}
.page a:hover{color: #fff; 背景: #0063DC; 境界線の色: #036; text-decoration: none;}
.page a:hover div{color: #FFF;cursor: pointer ! important;cursor: hand;}
*/
class pagelist{
var $page; //分页页
var $sql; //分页sql
var $img_path; //图标路径
var $img; //図标名
var $img_btn; //图标地址
var $page_size; //設置每页显表示条数
var $num_btn; // 数字の表示数を設定します
var $total_pages; //一共分数页
var $total_records; //一共有何条记录
var $url;
var $table;
var $new_sql; // 指定された SQL 句
var $db;
function __construct(){
global $db;
$this->db = $db;
$tmp_page = intval(trim($_GET["page"]));
$this->page = empty($tmp_page)?1:$tmp_page;
$this->set_table();
$this->page_size = 20;
$this->num_btn = 9;
$this->img_path = '/images/';
$this->img = array("ico_first.gif", "ico_front.gif", "ico_next.gif", "ico_last.gif");
}
function set_table(){
$this->table["tablename"] = "";
$this->table["id"] = "id";
$this->table["orderby"] = $this->table["id"];
$this->table["descasc"] = "DESC";
$this->table["fileds"] = "*";
$this->table["where"] = "";
}
function set_img(){
$this->img_btn[0] = "
";
$this->img_btn[1] = "
";
$this->img_btn[2] = "
";
$this->img_btn[3] = "
";
}
function set_show_page(){
$this->set_img(); //設定翻訳页图片路径
$this->set_url();
$this->set_total_records();
if ($this->total_records<$this->page_size){
$this->total_pages = 1;
}else{
$this->total_pages = ceil($this->total_records/$this->page_size);
}
if ($this->page>$this->total_pages){
$this->page = $this->total_pages;
}
}
function show_first_prv(){
if ($this->page==1)
$str = "
img_btn[0]." ;
".$this->img_btn[1]." ";
}else{
$str = "
".$this->img_btn[0]." "; //此处1は首页、page值は1
$str.= "
"。 $this->img_btn[1]." ";
}
return $str;
}
function show_next_last(){
if ($this->page>=$this->total_pages){
$str = "
"。 $this->img_btn[2]." ".$this->img_btn[3]." "; }else{ $str = "".$this->img_btn[2] ." "; $str.= "".$this->img_btn[3]." "; } return $str; } function show_num_text(){ $str = " 转到第 "; $str.= "url."'+document.getElementById('go_num_text').value;" style='font -family: Arial, Helvetica, sans-serif;font-weight:bold;font-size:14px;'>[Go] "; return $str; } function show_num_select(){ if ($this->total_pages $str = ""; for ($i=1; $i<=$this->total_pages; $i++){ $str.= " } $str.= " "; }else{ $str = ""; } return $str; } function show_num_btn(){ if ($this->page>=1 and $this->page<=$this->total_pages){ $tmp_p = ($this->num_btn-1 )/2; if (($this->page - $tmp_p) $start_p = 1; }else{ if (($this->page-$tmp_p)>$this->num_btn and ($this->page-$tmp_p)>($this->total_pages - $this-> ;num_btn+1)){ $start_p = $this->total_pages - $this->num_btn + 1; }else{ $start_p = $this->page - $tmp_p; } } if (($this->page+$tmp_p) < $this->total_pages){ $end_p = ($this->page + $tmp_p)<$this->num_btn ?$this->num_btn:($this->ページ + $tmp_p); if ($end_p>$this->total_pages){ $end_p = $this->total_pages; } }else{ $end_p = $this->total_pages; } } $str = ""; for ($i=$start_p; $i<=$end_p; $i++){ if ($i==$this->page) $str.= " ;".$i. " "; }else{ $str.= " ".$i." "; } } return $str; } function show_page_info(){ $str = " 共".$this->total_records."条/".$this->total_pages."页"; return $str; } function show_page(){ if ($this->total_records $this->set_show_page(); } $str = $this->total_pages>1 ? $this->show_first_prv().$this->show_num_btn().$this->show_next_last().$this->show_page_info().$this->show_num_text():""; return $str; } //总页数 function set_total_pages(){ $this->total_pages = ceil($this->total_records/$this->page_size); } //总记录数 function set_total_records(){ if ($this->total_records==0 or !isset($this->total_records)) { if (empty($this->count_sql ) and !empty($this->table["tablename"])){ $sql = "SELECT count(".$this->table["id"].") as count_id FROM `".$ this->table["tablename"]."` ".($this->table["where"]!=""?" WHERE ".$this->table["where"]:"" ); else{ $sql = preg_replace("/SELECT(.*?)FROM(.*?)/i", "SELECT count(id) AS count_id FROM\2", $this->sql); } $arr = $this->db->row_query_one($sql); $this->total_records = $arr["count_id"]; } } /* * sql に基づいて返されるデータ * $sql を指定する、制限を指定する必要はありません */ function get_rows_by_sql($sql){ $this->sql = $sql." LIMIT "。 $this->page_size*($this->page-1).",".$this->page_size; // 指定されたSQL; return $this->db->row_query($this->sql); } ($ tablename、$ where = ""、$ orderby = ""){$ this&gt; table ["orderby"] = $ orderby( page" =>$this->show_page(), //ページングコード "rows" =>$this->get_rows_by_sql(), //レコード数 "sum" $arr を回してください。 $ を回してくださいSQL_QUERYクエリSQLステートメント、$ row_count統計合計 $ arr ["rows"]; get_rows_by_sql($ sql_query); { $ this-> sql = "select".GT ;table["テーブル名"]."` ".($this->table["where"]!=""?" WHERE ".$this ->table["where"].' AND '.$this->table["id"].'>=':' WHERE '.$this->table["id"].'> ;=').'(SELECT '.$this-> table["id"].' FROM `'.$this->table["tablename"].'` ORDER BY '.$this-> table["id"].' LIMIT '.$this-> ;page_size*($this->page-1).', 1)'." ORDER BY ".$this->table["orderby" ]." ".$this->table["descasc" ]." LIMIT ".$this->page_size; ;table["テーブル名"]."` ".($this->table [ "どこ"]!=""?" WHERE ".$this->table["where"]:"")." ORDER BY ".$this->table["orderby"]." ".$ this->table["descasc"]." LIMIT ".$this->page_size*($this->page- 1).", ".$this->page_size; } //SELECT * FROM articles ORDER BY id DESC LIMIT 0, 20 //SELECT * FROM articles WHERE category_id = 123 AND id >= (SELECT id FROM articles ORDER BY id LIMIT 10000, 1) LIMIT 10 $this を返す->SQL; //SQL语句 function set_url(){ $arr_url = array(); parse_str($_SERVER["QUERY_STRING"], $arr_url); unset($arr_url["page"]); if (empty($arr_url)){ $str = "page="; }else{ $str = http_build_query($arr_url)."&page="; } $this->url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]."?".$str; } } ?>
$db_config["hostname"] = "1 27.0.0.1インチ; // 服务器地址
$db_config["username"] = "root"; //データベース库用户名
$db_config["パスワード"] = "root"; //データベース库密码
$db_config["database"] = "wap_blueidea_com"; //データ库名
$db_config["charset"] = "utf8";
$config["charset"] = "utf-8"; //网站编码
include('db.php');
include('pagelist.php');
$db = 新しい db();
$db->connect($db_config);
header("content-type:text/html;charset=".$config["charset"]);//设置页面编码
$pl = new pagelist();
$arr = $pl->get_rows('table_name');
設定解除($pl);
echo '
'; <br> print_r($arr); <br> echo ' ';
//指定特殊 sql 時期候
$pl = new pagelist();
$sql = 'SELECT * FROM `wap_article` AS a, `wap_article_info` AS b WHERE a.id=b.articleid';
$arr = $pl->get_rows_sql($sql);
設定解除($pl);
echo '
'; <br> print_r($arr); <br> echo ' ';
?>