|
|
|
สอบถามการแบ่งหน้า ไม่รู้ว่าผิดตรงไหนคะ มันยังผิดพลาดอยู่ |
|
|
|
|
|
|
|
สอบถามว่าทำไมมันยังไม่แบ่งหน้าให้คะ มันขึ้นมาบอกว่ามีทั้งหมด 2 หน้า แต่โชวืหมดเลย ไม่แบ่งหน้าเท่าที่เรากำหนดให้โชว์แค่ 10 เรื่อง แต่มันโชว์ทั้งหมด 20 เรื่อง รบกวนหน่อยคะ
Code (PHP)
<?
function pu_query($dbname,$sql,$ListPerPage=2)
{
global $page;
global $totalpage;
$result=mysql_db_query($dbname,$sql);
if (empty($page)) $page=1;
$num=mysql_num_rows($result);
$rt = $num%$ListPerPage;
//หาจำนวนหน้าทั้งหมด
$totalpage = ($rt!=0) ? floor($num/$ListPerPage)+1 : floor($num/$ListPerPage);
$goto = ($page-1)*$ListPerPage;
$sql .= " LIMIT $goto,$ListPerPage";
$result=mysql_db_query($dbname,$sql);
return $result;
}
function pu_pageloop($option="",$align="left")
{
global $page;
global $totalpage;
echo "<table align=center width=300% border=0 bordercolor=black cellspacing=0 cellpadding=2>\n";
echo "<tr><td align=$align>\n";
echo "<font color=#686898>\n";
// สร้าง link เพื่อไปหน้าก่อน-หน้าถัดไป
echo "กำลังแสดงหน้าที่ ";
if($page>1 && $page<=$totalpage) {
$prevpage = $page-1;
echo "<a href='".$_SERVER['PHP_SELF']."?page=$prevpage&$option' title='Back'><-</a>\n";
}
echo " <b>$page/$totalpage</b> ";
if($page!=$totalpage) {
$nextpage = $page+1;
echo "<a href='".$_SERVER['PHP_SELF']."?page=$nextpage&$option' title='Next'>-></a>\n";
}
echo "</font>\n";
echo "</td></tr>\n";
echo "<tr><td align=$align>\n";
// วนลูปแสดงเลขหน้าทั้งหมด แบบเป็นช่วงๆ ช่วงละ 25 หน้า
$b=floor($page/25);
$c=(($b*25));
if($c>1) {
$prevpage = $c-1;
echo "<a href='".$_SERVER['PHP_SELF']."?page=$prevpage&$option' title='25 หน้าก่อนนี้'><<</a> \n";
}
else{
echo "<<\n";
}
echo " <b>";
for($i=$c; $i<$page ; $i++) {
if($i>0)
echo "<a href='".$_SERVER['PHP_SELF']."?page=$i&$option'>$i</a> \n";
}
echo "<font size=2 color=red>$page</font> \n";
for($i=($page+1); $i<($c+25) ; $i++) {
if($i<=$totalpage)
echo "<a href='".$_SERVER['PHP_SELF']."?page=$i&$option'>$i</a> \n";
}
echo "</b> ";
if($c>=0) {
if(($c+25)<$totalpage){
$nextpage = $c+25;
echo "<a href='".$_SERVER['PHP_SELF']."?page=$nextpage&$option' title='25 หน้าถัดไป'>>></a> \n";
}
else
echo ">>\n";
}
else{
echo ">>\n";
}
echo "</td></tr>\n";
echo "</table>\n";
}// จบฟังก์ชั่น pu_split
?>
หน้าแสดง
Code (PHP)
<?php
include("pu_split.php");
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_RepairRS = sprintf("SELECT * FROM tbl_repair ORDER BY id_r DESC");
$RepairRS = mysql_query($query_RepairRS, $schoolsmile) or die(mysql_error());
$row_RepairRS = mysql_fetch_assoc($RepairRS);
$totalRows_RepairRS = mysql_num_rows($RepairRS);
$sql="SELECT * FROM tbl_repair ORDER BY id_r DESC";
$result=pu_query($database_schoolsmile,$sql,2);
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_GroupOwnerRS = sprintf("SELECT * FROM tbl_group ORDER BY id_g ASC");
$GroupOwnerRS = mysql_query($query_GroupOwnerRS, $schoolsmile) or die(mysql_error());
$row_GroupOwnerRS = mysql_fetch_assoc($GroupOwnerRS);
$totalRows_GroupOwnerRS = mysql_num_rows($GroupOwnerRS);
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_GroupPartRS = sprintf("SELECT * FROM tbl_part ORDER BY id_p ASC");
$GroupPartRS = mysql_query($query_GroupPartRS, $schoolsmile) or die(mysql_error());
$row_GroupPartRS = mysql_fetch_assoc($GroupPartRS);
$totalRows_GroupPartRS = mysql_num_rows($GroupPartRS);
mysql_select_db($database_schoolsmile, $schoolsmile);
$query_subGroupRS = sprintf("SELECT * FROM tbl_sub_group ORDER BY id_s ASC");
$subGroupRS = mysql_query($query_subGroupRS, $schoolsmile) or die(mysql_error());
$row_subGroupRS = mysql_fetch_assoc($subGroupRS);
$totalRows_subGroupRS = mysql_num_rows($subGroupRS);
$rob=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ระบบจัดการเว็บไซต์</title>
<link href="admin/adminstyle.css" rel="stylesheet" type="text/css">
</head>
<table width="1013" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1077" align="left"><table width="1008" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
<tr>
<td height="12" colspan="8" align="center" bordercolor="#FFFFFF" bgcolor="#E4CAAF"><center>
<img src="images/b_search.png" alt="" width="16" height="16" /> <strong><font>แสดงข้อมูลการแจ้งซ่อม</font></strong>
</center>
<div align="center">
<script language="JavaScript">
function check()
{
var v1 = document.SearchForm.keySearch.value;
if ( v1.length==0)
{
alert("กรุณาป้อนคำที่ค้นหา");
document.SearchForm.keySearch.focus();
return false;
}
else if ( v1=='กรุณาพิมพ์คำค้นที่นี่')
{
alert("กรุณาป้อนคำที่ค้นหา");
return false;
}
else
return true;
}
</script></strong><br /></td>
</tr>
<tr>
<td height="13" colspan="8" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF"> <img src="images/wait.gif" alt="" width="24" height="21" />= ขั้นตอนดำเนินการ <img src="images/correct.gif" alt="" width="21" height="21" />= ซ่อมเสร็จเรียบร้อย <img src="images/stop.gif" alt="" width="21" height="21" />= ส่งคืน(พัสดุ/ร้านจำหน่าย) <img src="images/b_new.png" alt="" width="16" height="16" />= แสดงรายละเอียด</td>
</tr>
<tr>
<td height="10" colspan="8" align="right" bordercolor="#FFFFFF">จำนวนทั้งหมด <?php echo "<font color=#FF0000><b>".$totalRows_RepairRS."</b></font>"; ?> รายการ </td>
</tr>
<tr>
<td width="36" height="25" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>ลำดับ</strong></td>
<td width="201" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>ชื่อ-สกุลผู้แจ้ง</strong></td>
<td width="170" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>สำนัก/กอง</strong></td>
<td width="154" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>วันที่แจ้งซ่อม</strong></td>
<td width="142" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>อุปกรณ์</strong></td>
<td width="152" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>อาการเสีย</strong></td>
<td width="46" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>สถานะ</strong></td>
<td width="131" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><strong>ผลการซ่อม</strong></td>
</tr>
<?php if ($totalRows_RepairRS > 0) { // Show if recordset not empty ?>
<?php do { ?>
<tr >
<td height="1" colspan="8" align="center" bordercolor="#999999" bgcolor="#CCCCCC"><img src="images/px1.gif" width="1" height="1"></td>
</tr>
<tr >
<td bordercolor="#999999" bgcolor="#F5F5F5">
<?php echo $rob++; ?>
<div align="center"></div></td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5"><?php echo $row_RepairRS['name']; ?> <?php echo $row_RepairRS['sname']; ?> </td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5">
<?php do {
if (!(strcmp($row_subGroupRS['id_s'], $row_RepairRS['id_s']))) {echo $row_subGroupRS['gsname'];
}
} while ($row_subGroupRS = mysql_fetch_assoc($subGroupRS));
$rows = mysql_num_rows($subGroupRS);
if($rows > 0) {
mysql_data_seek($subGroupRS, 0);
$row_subGroupRS = mysql_fetch_assoc($subGroupRS);
}
?> </td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5"><?php echo $row_RepairRS['date_in']; ?></td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5">
<?php do {
if (!(strcmp($row_GroupPartRS['id_p'], $row_RepairRS['id_p']))) {echo $row_GroupPartRS['pname'];
}
} while ($row_GroupPartRS = mysql_fetch_assoc($GroupPartRS));
$rows = mysql_num_rows($GroupPartRS);
if($rows > 0) {
mysql_data_seek($GroupPartRS, 0);
$row_GroupPartRS = mysql_fetch_assoc($GroupPartRS);
}
?> </td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5"><?php echo $row_RepairRS['ofservice']; ?></td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5">
<center><?php if ($row_RepairRS['r_status']=='' or $row_RepairRS['r_status']=='WAIT') {echo "<img src=images/wait.gif>";} else if ($row_RepairRS['r_status']=='OK') {echo "<img src=images/correct.gif>";} else {echo "<img src=images/stop.gif>";} ?></center></td>
<td align="left" bordercolor="#999999" bgcolor="#F5F5F5"><?php echo $row_RepairRS['r_summari']; ?> </td>
</tr>
<?php } while ($row_RepairRS = mysql_fetch_assoc($RepairRS)); ?>
<?php } // Show if recordset not empty ?>
</table>
<table align="right"><tr><td>
<? pu_pageloop("category=$category&rob=$rob"); ?>
</td></tr></table>
</td>
</tr>
</table>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-09-10 09:42:10 |
By :
NToo |
View :
640 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอน select ลองกำหนด limit ไปด้วยอ่าครับ
|
|
|
|
|
Date :
2013-09-10 11:26:37 |
By :
Freshy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรงไหนคะ
|
|
|
|
|
Date :
2013-09-10 11:41:32 |
By :
NToo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|