Home > Article > Backend Development > Example of ODBC data paging using PHP
$pagesize = 2; //Display the number of records on one page
$con = odbc_connect("access_test","","",SQL_CUR_USE_ODBC) or die("Unable to connect to ODBC data source access_test"); //Connect to an ODBC data source
$sql = "select count(*) as total from test"; //Get the total number of records SQL statement
$rst = odbc_exec($con,$sql) or die("$sql query error"); //Execute the SQL statement to obtain the total number of records
$recordcount = odbc_result($rst,1); //Get the total number of records, you can also use $recordcount = odbc_result($rst,"total");
odbc_free_result($rst); //Release resources
$pagecount = bcdiv($recordcount+$pagesize-1,$pagesize,0); //Calculate the total number of pages
if(!isset($page)) $page = 1; //If no page number is specified, the default is to display the first page
if($page<1) $page = 1; //If the page number is smaller than 1, display the first page
if($page>$pagecount) $page = $pagecount; //If the page number is greater than the total number of pages, display the last page
if($page>0){ //The page number is larger than 0, indicating that there is data
echo '>> paging ';
echo 'Homepage ';
If($page>1){
echo 'Previous page ';
}
else{
echo 'previous page';
}
If($page<$pagecount){
echo 'Next page ';
}
else{
echo 'next page';
}
echo 'Last page ';
echo 'Page: ' . $page . '/' . $pagecount . 'Page ';
echo $pagesize . 'Article/page';
echo 'total' . $recordcount . 'articles';
$sql = "select * from test"; //Get data SQL statement
$rst = odbc_exec($con,$sql) or die("$sql query error"); //Execute the SQL statement to obtain data
$fieldcount = odbc_num_fields($rst); //Get the total number of fields
echo '
' . odbc_field_name($rst,$i) . ' | '; //Display the $i-th field name|
---|---|
'; | ' . $field . ' | ';
The above introduces the example of using PHP to implement ODBC data paging, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.