Home  >  Article  >  Backend Development  >  Paging result set implementation code_PHP tutorial

Paging result set implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:47:321187browse

Copy code The code is as follows:

@mysql_connect("localhost", "root","1981427" ) //Connect to the database server
or die("Database server connection failed");
@mysql_select_db("test") //Select the database mydb
or die("The database does not exist or is unavailable") ;
$query = @mysql_query("select * from tablename1") //Execute the SQL statement used to calculate the number of pages
or die("SQL statement execution failed");
$pagesize = 5; //Set the number of records per page
$sum = mysql_numrows($query); //Calculate the total number of records
if($sum % $pagesize == 0) //Calculate the total number of pages
$total = (int)($sum/$pagesize);
else
$total = (int)($sum/$pagesize) + 1;
if (isset($_GET['page']) ) //Get page number
{
$p = (int)$_GET['page'];
}
else
{
$p = 1;
}
$start = $pagesize * ($p - 1); //Calculate the starting record
//Execute the SQL statement to query the current page record
$query = @mysql_query("select * from tablename1 limit $start, $pagesize")
or die("SQL statement execution failed");
echo ""; //Output table header
//Output through loop All records from row 0 to the largest row
while($row = mysql_fetch_array($query))
{
$serial_no = $row['id']; //Output row $i serial_no column
$name = $row['username']; //Output the name column of row $i
$salary = $row['password']; //Output the salary of row $i column
echo "";
echo "";
echo "";
echo "";
echo "";
}
echo "
$serial_no$name$salary
"; //Output table tail
if ($p > 1) //When the current page is not the first page, output the link to the previous page
{
$prev = $p - 1;
echo "Previous page ";
}
if($p < $total) //The current page is not the last page When, output the link to the next page
{
$next = $p + 1;
echo "";
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319928.htmlTechArticleCopy the code as follows: ?php @mysql_connect("localhost", "root","1981427") // Connect to the database server or die("Database server connection failed"); @mysql_select_db("test") //Select number...