Home >Backend Development >PHP Tutorial >China Welfare Lottery 15 Pick 5 Lottery Results PHP result set paging implementation code
Copy the 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 process for calculating the number of pages SQL statement
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 the 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 "
$serial_no | ";$salary | "; /Output the end of the table