SoFunction
Updated on 2025-04-08

Use ODBC pagination display

<?php


$pagesize = 3;//Set the number of displays per page

//Calculate the total number of records
$rs_num = "select count(*) as id from table";
$rs_num = odbc_exec($conn_id,$rs_num);
$rs_num = odbc_result($rs_num,"id");

//Calculate the total number of pages
$pagecount = $rs_num / $pagesize;
$pagecount1 = intval($pagecount);//Fill the total number of pages
$compare = $pagecount - $pagecount1;
switch ($compare){
case "0":
$pagecount = $pagecount1;//Total number of pages
break;
default :
$pagecount1++;
$pagecount = $pagecount1;//Total number of pages
break;
};
if ($pagecount == 0)$pagecount++;


$fpages = $pages-1;
$bpages = $pages+1;



?>
<table>
<tr>
<td>
Total <?php echo $pagecount ?> pages
<?php if($pages != 1)echo "<a href=show.php3?pages=1>";?>Homepage<?php if($pages != 1)echo "</a>"; ?>  Homepage<?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != 1)echo "<a href=show.php3?pages=".$fpages.">"; ?> Previous page <?php if($pages != 1)echo "</a>"; ?>   Previous page <?php if($pages != 1)echo "</a>"; ?>
<?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$bpages.">"; ?>Last page<?php if($pages != $pagecount)echo "</a>"; ?> <?php if($pages != $pagecount)echo "<a href=show.php3?pages=".$pagecount.">"; ?>
Last page <?php if($pages != $pagecount)echo "</a>"; ?>
</td>
</tr></table>
<?php
$firstshow = ($pages-1)*$pagesize+1;//Determine the first record on each page

//Find out the record number of the first record
$query_string = "SELECT * FROM table Order By id DESC";
$query_string = odbc_exec($conn_id,$query_string);
odbc_fetch_into($query_string,$firstshow,&$idarea);
$idsql = $idarea[0];

//Location search
if ($pages == $pagecount) {
$rs = "SELECT * FROM table where id <= '".$idsql."' Order By id DESC";
}else{
$rs = "SELECT Top ".$pagesize." * FROM table where id <= '".$idsql."' Order By id DESC";
};

$rs = odbc_exec($conn_id,$rs);

//Show records
while(odbc_fetch_row($rs)){



};
?>

<?php
//Close the connection
odbc_close($conn_id);
?>


[The copyright of this article is jointly owned by the author and Aoso.com. If you need to reprint it, please indicate the author and source]