An example of paging display of ODBC data using PHP_PHP tutorial

WBOY
Release: 2016-07-21 16:01:42
Original
915 people have browsed it

$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 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 get 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") here ;
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 greater than 1 If the page number is small, the first page will be displayed
if($page>$pagecount) $page = $pagecount; //If the page number is larger than the total number of pages, the last page will be displayed

if($page> 0){ //The page number is larger than 0, indicating that there is data
echo '>> paging';
echo 'Home page ';
if($page>1){
echo ' ';
}
else{
echo 'Previous page';
}
if($page<$pagecount){
echo '< ;a href="' . $PHP_SELF . '?page='. ($page+1) . '">Next page
';
}
else{
echo ' Next page';
}
echo 'Last page ';
echo 'Page: ' . $page . '/' . $pagecount . 'Page';
echo $pagesize . 'Bar/page';
echo 'Total' . $recordcount . 'Bar';

$sql = "select * from test"; //Get data SQL statement
$rst = odbc_exec($con,$sql) or die("$sql query error"); //Execute to get data SQL statement

$fieldcount = odbc_num_fields($rst); //Get the total number of fields

echo '

';
echo '';
for($i=1;$i<=$fieldcount;$i++){
echo ''; //Display $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 '
' .odbc_field_name($rst, $i) . '
' . ;
                                                                                                                                                                                                                                                                                    ; 🎜>}
else{
echo "No data";
}

odbc_close($con); //Close the connection and release resources
?>



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316761.htmlTechArticle$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 co...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!