$page = $_GET['page']; if (empty($page)) { $page = 1; }
//$sql_list = "select * from ag1"; //$result = odbc_exec($conn,$sql_list); $rs = "select * from ag1";//แบ่งหน้าเหมือน limit ของ mysql $result = odbc_exec($conn,$rs); $sql_list = odbc_exec($conn, "SELECT count(*) as expr1 FROM ag1") or die (mysql_error());
SELECT TOP 2 * FROM.......
มีความหมายเหมือนกับ
SELECT * FROM.....LIMIT 2
จากโค้ดนี้จะแก้ไขอย่างไรค่ะ ไม่รู้จริง ๆ ค่ะได้ลองหลายครั้งแล้ว มันไม่แบ่งหน้าให้แต่นับจำนวนให้แล้ว
<? include("../conn_lee.inc");
$pagelen = 50;
$rang = 3;
$page = $_GET['page'];
if (empty($page))
{
$page = 1;
}
//$sql_list = "select * from ag1";
//$result = odbc_exec($conn,$sql_list);
$rs = "select * from ag1";//แบ่งหน้าเหมือน limit ของ mysql
$result = odbc_exec($conn,$rs);
$sql_list = odbc_exec($conn, "SELECT count(*) as expr1 FROM ag1") or die (mysql_error());
//odbc_fetch_row($sql_list);
$num_rows = odbc_result($sql_list, 'expr1');
echo "expr1 :".$num_rows;
//$totalnumber = $num_rows = odbc_num_rows($result);
$totalpage = ceil($num_rows/$pagelen);
echo "<br>totalpage :".$totalpage;
$goto = ($page-1) * $pagelen;
//echo "<br>goto :".$goto;
$start = $page - $rang;
$end = $page + $rang;
if($start <=1)
{
$start = 1;
}
if($end >= $totalpage)
{
$end = $totalpage;
}
$sql = odbc_exec($conn, "SELECT * FROM ag1") or die (mysql_error());
//$result = odbc_exec($conn,$sql_list);
$i = 1;
while($fetch=odbc_fetch_array($result))
{
$id_ap = $fetch[id_pb2];
$branch = $fetch[branch];
$color1 = ($i % 2)? '#FFDCA8' : '#FFE3BB';
?>
<tr bgcolor="<? echo $color1; ?>" class="smalltxtCopy31">
<td height="28" class="type_3">
<?=$i?></td>
<td class="type_3">
<?=$fetch[วันบันทึกนำส่ง]?></td>
<td class="type_3"><a href="detail_pb2.php?id_pb2=<?=$fetch[id_pb2];?>"target=_blank>
<?=$fetch[เลขนำส่ง];?>
</a></td>
<td class="type_3"><font class="type_3"> </font> <?=$fetch[คำนำหน้า]; ?><?=$fetch[ชื่อ]; ?> <?=$fetch[สกุล]; ?></td>
<td class="type_3"><font class="type_3">
<?=$fetch[เลขที่บัตร]; ?>
</font></td>
<td class="type_3"><font class="type_3"> </font> <font class="type_3"> </font>
<font class="type_3"> </font><font class="type_3">
<?
$refin = $fetch[ยอดเงิน];
$shoo = number_format($refin,2,'.',',');
echo $shoo;
?>
</font></td>
<td class="type_3">
<font class="type_3"> </font>
<?=$fetch[วันรับชำระ]; ?></td>
</tr>
<?
$i++;
}
?>
</table>
<table width="727" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="18"><?
echo "<br>";
echo "<font class='type_2'>พบจำนวนทั้งสิ้น </font><font class='type_6Copy3'>$num_rows</font><font class='type_2'> รายการ</font>";
if($num_rows == "") {
echo " <font class='type_6Copy3'>ไม่มีข้อมูล</font>"; }
if ($page > 1) {
$back = $page - 1;
echo " <font class='type_6Copy1'><a href=$PHP_SELF?page=1>"."แรกสุด</a></font>
";
echo "<font class='type_6Copy1'><a href=$PHP_SELF?page=". $back .">ก่อนหน้า</a></font>";
if ($start > 1) { echo "....."; }
}
For ($i=$start ; $i<=$end ; $i++) {
if ($i == $page ) {
echo " <b><font class='type_6Copy1'>หน้าที่ $i</font></b>";
} else {
echo " <font class='type_6Copy1'><a href=$PHP_SELF?page=$i>$i</a></font>
";
}
}
if ($page < $totalpage) {
$next = $page +1;
if ($end < $totalpage) { echo "....."; }
echo "<font class='type_6Copy1'><a href=$PHP_SELF?page=".$next.">
ถัดไป</a></font>";
echo " <font class='type_6Copy1'><a href=$PHP_SELF?page=".$totalpage.">ท้ายสุด</a></font>
";
}
odbc_close($conn);