Using PHP to implement ODBC data pagination display a case _php tutorial

Source: Internet
Author: User
$pagesize = 2; The number of records displayed on a page

$con = Odbc_connect ("Access_test", "" "," "", Sql_cur_use_odbc) or Die ("Cannot connect to ODBC data source Access_test"); Connect an ODBC data source
$sql = "SELECT count (*) as total from Test"; Get Total Records SQL statement
$rst = Odbc_exec ($con, $sql) or Die ("error $sql query"); Execute get Total records SQL statement
$recordcount = Odbc_result ($rst, 1); Get the total number of records, which can also be used here $recordcount = Odbc_result ($rst, "totals");
Odbc_free_result ($rst); Freeing resources

$pagecount = Bcdiv ($recordcount + $pagesize-1, $pagesize, 0); Figure out the total number of pages

if (!isset ($page)) $page = 1; If no page numbers are specified, the default is to show the first page
if ($page <1) $page = 1; If the page number is smaller than 1, the first page is displayed
if ($page > $pagecount) $page = $pagecount; If page numbers are larger than the total number of pages, the last page is displayed

if ($page >0) {//page number is greater than 0, indicating data
Echo ' >> paging ';
Echo ' Home ';
if ($page >1) {
Echo ' front page ';
}
else{
Echo ' front page ';
}
if ($page < $pagecount) {
Echo ' Back Page ';
}
else{
Echo ' Back Page ';
}
Echo ' last ';
Echo ' page: '. $page. '/' . $pagecount. ' Page ';
Echo $pagesize. ' Bar/page ';
Echo ' Total '. $recordcount. ' article ';

$sql = "SELECT * from Test"; Get data SQL statement
$rst = Odbc_exec ($con, $sql) or Die ("error $sql query"); Execute GET Data SQL statement

$fieldcount = Odbc_num_fields ($rst); Total number of fields obtained

Echo '
























'; Echo ' '; for ($i =1; $i <= $fieldcount; $i + +) {echo ' '; Show $i field name} Echo ' '; $rowi = ($page-1) * $pagesize +1; for ($i =0; $i < $pagesize; $i + +) {echo ' '; if ($rowi > $recordcount) {for ($j =0; $j < $fieldcount; $j + +) {echo ' '; }} else{Odbc_fetch_into ($rst, $rowi,& $row); for ($j =0; $j < $fieldcount; $j + +) {$field = $row [$j]; if ($field = = ") $ field = '; Echo ' '; } $rowi = $rowi +1; } Echo ' '; } Echo '
. Odbc_field_name ($rst, $i). '
' . $field. '
';

Odbc_free_result ($rst); Freeing resources
}
else{
echo "No data";
}

Odbc_close ($con); Close the connection and release the resource
?>


http://www.bkjia.com/PHPjc/316761.html www.bkjia.com true http://www.bkjia.com/PHPjc/316761.html techarticle $pagesize = 2;//page shows the number of records $con = Odbc_connect (access_test,,, Sql_cur_use_odbc) or die (Cannot connect to ODBC data source access_test); Connect an ODBC data source $sql = Select Co ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.