PHP mysql database operation paging class_PHP tutorial
/*
* mysql数据库 分页类
* @package pagelist
* @author yytcpt(无影)
* @version 2008-03-27
* @copyrigth http://www.d5s.cn/
*/
/*
* 分页样式
.page{float: left;font: 11px Arial, Helvetica, sans-serif; padding:6px 0; margin: 0px 10%; margin-top: 10px;}
.page a, .page strong{padding: 2px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.page a:visited{padding: 2px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.page .break{padding: 2px 6px; border: none; background: #fff; text-decoration: none;}
.page strong{padding: 2px 6px; border-color: #999; font-weight: bold; font-size: 13px; vertical-align: top; background: #fff;}
.page a:hover{color: #fff; background: #0063DC; border-color: #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_recordspage_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 = "".$this->img_btn[0]." ".$this->img_btn[1]."";
}else{
$str = "url."1"."'>".$this->img_btn[0]." "; //此处1为首页,page值为1
$str.= "url.($this->page-1)."'>".$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 = "url.($this->page+1)."'>".$this->img_btn[2]." ";
$str.= "url.$this->total_pages."'>".$this->img_btn[3]."";
}
return $str;
}
function show_num_text(){
$str = " 转到第 page."' style="max-width:90%"/> 页 ";
$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 = " ";
}else{
$str = "";
}
return $str;
}
function show_num_btn(){
if ($this->page>=1 and $this->pagetotal_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) total_pages){
$end_p = ($this->page + $tmp_p)num_btn?$this->num_btn:($this->page + $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 if ($i==$this->page){
$str.= " ".$i." ";
}else{
$str.= " url.$i."'>".$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时,不必指定limit
*/
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);
}
/
function get_rows($tablename, $where="", $orderby=""){
$this->table["tablename"] = $tablename;
$this->table ["where"] = $where;
$orderby ? $this->table["orderby"] = $orderby : "";
$arr = array(
"page" => $this->show_page(), ‐ "rows" => $this->total_records , Statement, $row_count total statistics
*/
function get_rows_sql($sql_query, $row_count=0) {
$this->total_records = $row_count;
$arr["rows"] = $this->get_ rows_by_sql($sql_query);
$arr["page"] 🎜> }
function get_sql(){
if ($this->total_records>10000) {
$this->sql = "SELECT ".$this->table["fileds"]." FROM ` ".$this->table["tablename"]."` ".($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;
." FROM `".$this->table["tablename"]."` ".($this->table["where"]!=""?" 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
return $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"] = "127.0.0.1"; //服务器地址
$db_config["username"] = "root"; //数据库用户名
$db_config["password"] = "root"; //数据库密码
$db_config["database"] = "wap_blueidea_com"; //数据库名称
$db_config["charset"] = "utf8";
$config["charset"] = "utf-8"; //网站编码
include('db.php');
include('pagelist.php');
$db = new db();
$db->connect($db_config);
header("content-type:text/html;charset=".$config["charset"]);//设置页面编码
$pl = new pagelist();
$arr = $pl->get_rows('table_name');
unset($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);
unset($pl);
echo '
'; <br> print_r($arr); <br> echo '';
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools