|
|
|
ช่วยดูโค้ดนับจำนวน Record ให้หน่อยครับ พอแบ่งหน้าแล้วมันนับมั่วครับ |
|
|
|
|
|
|
|
โค้ด เขียนจาก Dream ครับ
Code (PHP)
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_ps = 20;
$pageNum_ps = 0;
if (isset($_GET['pageNum_ps'])) {
$pageNum_ps = $_GET['pageNum_ps'];
}
$startRow_ps = $pageNum_ps * $maxRows_ps;
mysql_select_db($database_connect, $connect);
$query_ps = "SELECT * FROM history";
$query_limit_ps = sprintf("%s LIMIT %d, %d", $query_ps, $startRow_ps, $maxRows_ps);
$ps = mysql_query($query_limit_ps, $connect) or die(mysql_error());
$row_ps = mysql_fetch_assoc($ps);
if (isset($_GET['totalRows_ps'])) {
$totalRows_ps = $_GET['totalRows_ps'];
} else {
$all_ps = mysql_query($query_ps);
$totalRows_ps = mysql_num_rows($all_ps);
}
$totalPages_ps = ceil($totalRows_ps/$maxRows_ps)-1;
$queryString_ps = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_ps") == false &&
stristr($param, "totalRows_ps") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_ps = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_ps = sprintf("&totalRows_ps=%d%s", $totalRows_ps, $queryString_ps);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url(../images/bg.gif);
}
.style11 {font-family: Tahoma; font-size: 14px; font-weight: bold; color: #0000FF; }
.style12 {font-size: 13px}
.style13 {color: #0000FF; font-family: Tahoma;}
-->
</style></head>
<body>
<table width="100%" border="1" cellspacing="0">
<tr>
<td width="7%"><div align="center" class="style11">ลำดับที่</div></td>
<td width="24%"><div align="center" class="style11">ชื่อ-สกุล</div></td>
<td width="17%"><div align="center" class="style11">รหัสพนักงาน</div></td>
<td width="17%"><div align="center" class="style11">ตำแหน่ง</div></td>
<td width="17%"><div align="center" class="style11">วันลาพักผ่อนคงเหลือ</div></td>
<td width="18%"><div align="center" class="style11">แก้ไข / ลบ</div></td>
</tr>
<?
//$i = 1;
?>
<?php do {
$i++;
if($pageNum_ps > 1) //ตรงนี้หละครับ ที่ผมทำแล้วไม่ถูกไม่รู้ว่าจะแก้ยังไงครับ
{
$i = ($maxRows_ps * ($pageNum_ps)) + 1;
}
?>
<tr>
<td><div align="center" class="style12"><?=$i;?></div></td>
<td><div align="center" class="style12"><span class="style13"><?php echo $row_ps['name']; ?></span></div></td>
<td><div align="center" class="style12"><span class="style13"><?php echo $row_ps['idmember']; ?></span></div></td>
<td><div align="center" class="style12"><span class="style13"><?php echo $row_ps['position']; ?></span></div></td>
<td><div align="center" class="style12"><span class="style13"><?php echo $row_ps['va_have_total']; ?></span></div></td>
<td><div align="center" class="style12"><span class="style13"><img src="../images/edit.png" width="20" height="21" /> <img src="../images/delete.png" width="20" height="21" /></span></div></td>
</tr>
<?php } while ($row_ps = mysql_fetch_assoc($ps));
$i = 1;
?>
</table>
<br />
<table border="0" align="center">
<tr>
<td><?php if ($pageNum_ps > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_ps=%d%s", $currentPage, 0, $queryString_ps); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_ps > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_ps=%d%s", $currentPage, max(0, $pageNum_ps - 1), $queryString_ps); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td><?php if ($pageNum_ps < $totalPages_ps) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_ps=%d%s", $currentPage, min($totalPages_ps, $pageNum_ps + 1), $queryString_ps); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td><?php if ($pageNum_ps < $totalPages_ps) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_ps=%d%s", $currentPage, $totalPages_ps, $queryString_ps); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($ps);
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-03-23 09:19:41 |
By :
addy_it |
View :
1557 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ... แต่ผมอยากปรบใช้กับโค้ด ด้านบนนี้อะครับ... ต้องปรับตรงไหนบ้างครับ
|
|
|
|
|
Date :
2012-03-23 11:22:58 |
By :
addy_it |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|