An example of using PHP to display ODBC data by page

Source: Internet
Author: User
Use PHP to display ODBC data by page. read this example and use PHP to display ODBC data by page. $ pagesize = 2; // number of records displayed on one page $ con = odbc_connect (access_test ,,, SQL _CUR_USE_ODBC) ordie (unable to connect to the ODBC data source access_test); // connect to an ODBC data source $ pagesize = 2; // The number of records displayed 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"; // obtain the total number of records SQL statement
$ Rst = odbc_exec ($ con, $ SQL) or die ("$ SQL query error"); // execute an SQL statement that retrieves the total number of records
$ Recordcount = odbc_result ($ rst, 1); // you can use $ recordcount = odbc_result ($ rst, "total") to obtain the total number of records ");
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 first page is displayed by default.
If ($ page <1) $ page = 1; // if the page number is smaller than 1, the first page is displayed.
If ($ page> $ pagecount) $ page = $ pagecount; // if the page number is larger than the total page number, the last page is displayed.

If ($ page> 0) {// The page number is greater than 0, indicating that data exists.
Echo '> pagination ';
Echo 'homepage ';
If ($ page> 1 ){
Echo 'previous page ';
}
Else {
Echo 'previous page ';
}
If ($ page <$ pagecount ){
Echo 'back page ';
}
Else {
Echo 'back page ';
}
Echo 'Last page ';
Echo 'Page Times: '. $ page.'/'. $ pagecount.' page ';
Echo $ pagesize. 'entries/page ';
Echo 'total'. $ recordcount. 'barri ';

$ SQL = "select * from test"; // SQL statement for retrieving data
$ Rst = odbc_exec ($ con, $ SQL) or die ("$ SQL query error"); // execute an SQL statement to obtain data

$ Fieldcount = odbc_num_fields ($ rst); // retrieves the total number of fields

Echo'
























';Echo' ';For ($ I = 1; $ I <= $ fieldcount; $ I ++ ){Echo' '; // Display the $ 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); // release resources
}
Else {
Echo "no data ";
}

Odbc_close ($ con); // close the connection and release resources
?>


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.