Home > Backend Development > PHP Tutorial > Integrated the previous PHP database connection class~~to make a paging class!_PHP tutorial

Integrated the previous PHP database connection class~~to make a paging class!_PHP tutorial

WBOY
Release: 2016-07-21 16:00:10
Original
833 people have browsed it

I don’t know if there is a future for learning PHP~ The more I write, the more boring I get

Class createdb //The beginning of the class
{
var $db= "localhost";// Database address;
var $dbname = "root";//Username;
var $dbpwd = "";//Password;
var $dbtable = "mysql";//Database used
var $conn; //Database connection;
var $result; //Result set
var $mysql; //Executed mysql
var $row; //Find data in the result set
function createconn() //This class method is to start a conn connection and then start selecting the database
{
$this->conn = mysql_connect($this->db,$this->dbname,$ this->dbpwd);
mysql_select_db($this->dbtable,$this->conn);
}
function getresule() //This is to get a result set
{
$this->result = mysql_query($this->mysql,$this->conn);
}
function getrow() //Create a forward result set pointer
{
$this->row = mysql_fetch_array($this->result);
return $this->row;
}
function closedatabase()
{
mysql_close($this->conn);
}
}//The class ends and starts calling the class to read the mysql database data.
//Debug the database connection code! Unnecessary.
/* $bb = new createdb; //Class instantiation
$bb->createconn();//Call class connection
$bb->mysql="select * from friends_conf";
$bb->getresule(); //Call the class to get the result set
while($bb->getrow()){ //Call the class to create a pointer and read the data forward in a loop,
echo ($bb->row["confname"]);
echo($bb->row["confvalue"]);
}*/
?>
//Page break Class~ Inherits the above method
Class pagefy extends createdb{
var $nametatol; //Total number of records
var $namemust = 1; //Each page wants Number of records to be displayed
var $pageall;
var $i = 1;
var $m;
var $p = 8; //Page number to be displayed;
var $a ;
function gettatol() //How to get the total number of records
{ //Connect to the database first
$this->nametatol = $this->row[0]; //Total Number of records
}
function getpage() //Get the total number of pages
{
$this->pageall = $this->nametatol % $this->namemust;
if($this->pageall)
{
$this->pageall = (int)($this->nametatol / $this->namemust) + 1;
return $this ->a = $this->pageall ;
}
else
{
return $this->a = $this->pageall = (int)($this-> ;nametatol / $this->namemust);
}
}
function num_pl() //Page number display
{
$this->pageall = $this->pageall - ($this->pageall - $this->p);
while($this->pageall)
{
echo("$this->i");
echo(" "); //Add the style you want to display
$this->i++;
$this->pageall =$this->pageall -1;
}
}
function get_num_pl() //Get the previous parameter of LIMIT (starting ROW number)
{
$this->m = $_GET["n"] * $this->namemust - $this->namemust;
}
function showpage() //Show paginated content
{
$this->createconn();
$this->mysql="select * from friends_conf limit $this-> m ,$this->namemust";
$this->getresule();
while($this->getrow())
{
echo($this-> row["confname"]); //Add the fields you want to read out yourself
echo($this->row["confvalue"]);
}
}
function firstpage () //Homepage
{
echo("Homepage");
}
function backpage() //Previous page
{
if($this->i = $_GET["n"] - 1)
{
echo("
Previous page");
}
}
function nextpage() //Next page
{
$ this->i = $_GET["n"] + 1;
if($this->i <= $this->a)
{
echo("
Next page");
}
}
function footpage() //Last page
{
echo("
Last page");
}
}
?>
$mm = new pagefy;
$mm->createconn();
$mm->mysql="select count(* ) from friends_conf";
$mm->getresule();
$mm->closedatabase();
$mm->getrow();
$mm->gettatol ();
$mm->getpage();
$mm->num_pl();
$mm->get_num_pl();
$mm->showpage() ;
$mm->closedatabase();
$mm->firstpage();
$mm->backpage();
$mm->nextpage();
$mm->footpage();
?>
This class has been debugged! It is very easy to use~~~~~~~~~~~~~~~~
The class is Your sword~ If you don’t refine it in advance, it will be difficult to practice it until the fight!~ You will be dead~~
As soon as I have time! I will write a functional class~~~~~~                               🎜>I should say that my category is relatively simple~~~Ask if you don’t understand~

http://www.bkjia.com/PHPjc/317218.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317218.htmlTechArticleI don’t know if there is a future for learning PHP~ Hey, the more I write, the more boring I become? php Classcreatedb//The beginning of the class { var$ db="localhost";//Database address; var$dbname="root";//User name; var$dbpwd="";//Password; var$...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template