|
|
|
รบกวนช่วยดูการแบ่งหน้าให้หน่อยค่ะ อยากกำหนดข้อมูลให้ขึ้นแค่ 10 ข้อมูล |
|
|
|
|
|
|
|
อยากกำหนดให้ข้อมูลขึ้นแค่ 10 ข้อมูลค่ะ ช่วยดูโค้ดให้หน่อยนะคะ
ขอบคุณมากๆ ค่ะ Code (PHP)
<?php require_once('../Connections/Myconnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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_Myconnect, $Myconnect);
$query_Recordset1 = "SELECT * FROM customer";
$Recordset1 = mysql_query($query_Recordset1, $Myconnect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$Per_Page = 2; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
?>
<!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=utf-8" />
<title>seeall_user</title>
</head>
<body background="bg.jpg" >
<?php require('topmenu.css');?>
<center>
<br />
<table width="1229" height="152" border="0">
<tr>
<td width="1223" height="135" border="0"><center>
<img src="GSB_Logo.png" width="452" height="158" />
</center></td>
</tr>
</table>
<table width="1254" height="31" border="0">
<tr>
<td width="705" height="25" >
<font color="#FFFFFF"> <form action=" " method="post" autocomplete="on">
<div id="headBottom">
<div id="topmenu">
<ul>
<li><a href="index_user.php"><span>หน้าแรก</span></a>
<a href="Account Summary.php"><span>เพิ่มบัญชีลูกค้า</span></a>
<a href="edit account.php"><span>แก้ไขบัญชีลูกค้า</span></a>
<a href="search_user.php"><span>ค้นหาแฟ้มงาน</span></a>
<a href="seeall_user.php"><span>ดูแฟ้มงานทั้งหมด</span></a>
<a href="contact.php"><span>แก้ไขข้อมูลส่วนตัว</span></a>
</li>
</ul>
</div>
<div class="bttnCheck"></div>
</div>
</form>
</font>
<div align="right" size="16">ยินดีต้อนรับ:<font color="#6633CC"><? echo $_SESSION["user"];?></font> <a href="login.php">Logout</a></div></td>
</tr>
</table>
<table width="1234" border="0">
<tr>
<td height="407" bgcolor="#FFFFFF"><table width="1245" border="0">
<tr>
<td height="407" align="center" valign="top" bgcolor="#FFFFFF"><center>
<legend align="left" class="style1"><u><br /><font color="#333333" size="+1">แฟ้มบัญชีทั้งหมด</font></u></legend></center>
<center><br />
<table border="0">
<tr align="center" valign="middle" bgcolor="#4D4D4D">
<td width="166" bgcolor="#666699"><font color="#CCCCCC">ประเภทสินเชื่อ</font></td>
<td width="165" bgcolor="#666699"><font color="#CCCCCC">เลขที่บัญชี</font></td>
<td width="164" bgcolor="#666699"><font color="#CCCCCC">ชื่อ</font></td>
<td width="165" bgcolor="#666699"><font color="#CCCCCC">นามสกุล</font></td>
<td width="43" bgcolor="#666699"><font color="#CCCCCC">รายงาน</font></td>
</tr>
<?php do { ?>
<tr align="center" valign="middle">
<td align="left" valign="middle" bgcolor="#CCCCCC"><?php echo $row_Recordset1['n_credit']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['id_credit']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['name']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['lastname']; ?></td>
<td><a href="report.php?id_credit=<?php echo $row_Recordset1['id_credit']; ?>" ><img src="report.png" width="37" height="28" /></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</center>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
?>
</td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="1248" height="31" border="0">
<tr>
<td width="705" height="1" bgcolor="#6666CC">
</td>
</tr>
</table>
</center>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax
|
|
|
|
|
|
Date :
2014-11-17 00:45:59 |
By :
jibb |
View :
752 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
094. $strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
095. $Recordset1 = mysql_query($query_Recordset1, $Myconnect) or die(mysql_error());
|
|
|
|
|
Date :
2014-11-17 02:42:07 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
069. $Per_Page = 2; // Per Page ถูกกำหนดให้แสดง 2 รายการ
|
|
|
|
|
Date :
2014-11-17 07:19:11 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
require_once('../Connections/Myconnect.php');
mysql_select_db($database_Myconnect, $Myconnect);
// mysql_select_db เอาเข้าไปอยู่ใน Myconnect.php เลยนะครับ เพราะมันต้องทำคู่กันอยู่แล้ว
// function ข้างล่างนี้ ทำแค่อันเดียวก็พอ
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
if (PHP_VERSION < 6) $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;
}
}
//$query_Recordset1 = "SELECT * FROM customer"; คิวรี่ แค่ จำนวน record ไม่ต้องคิวรี่ ท้้งหมด
//$Recordset1 = mysql_query($query_Recordset1, $Myconnect) or die(mysql_error());
//$row_Recordset1 = mysql_fetch_assoc($Recordset1);
// $totalRows_Recordset1 = mysql_num_rows($Recordset1);
// ประกาศ $totalRows แต่เอาไปใช้ เป็น $Num_Rows;
$query_Recordset1 = "SELECT count(*) FROM customer";
$Recordset1 = mysql_query($query_Recordset1, $Myconnect) or die(mysql_error());
list($Num_Rows) = mysql_fetch_row($Recordset1);
mysql_free_result($Recordset1);
$Per_Page = 10; // Per Page
//$Page = $_GET["Page"];
//if(!$_GET["Page"])
//{
// $Page=1;
//}
$Page = isset($_GET['Page'])? $_GET['Page'] : 1; // chedk ตัวแปบ วิธีนี้ ง่ายกว่าครับ ไม่มี warning ให้เป็นขยะ
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
//$Page_Start = (($Per_Page * $Page) - $Per_Page);
$Page_Start = ( $Per_Page * $Page) - $Per_Page;
/*
if($Num_Rows<=$Per_Page){
$Num_Pages =1;
}else if(($Num_Rows % $Per_Page)==0){
$Num_Pages =($Num_Rows/$Per_Page) ;
}else{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
*/
$Num_Page=ceil( $Num_Rows / $Per_Page); // หาจำนวน หน้า แบบ สั้นๆ ง่ายๆ
$strSQL = "SELECT * FROM customer";
$strSQL .=" order by CustomerID ASC LIMIT $Page_Start , $Per_Page";
// ผิดตรงนี ประกาศ แล้วไม่ได้นำไปใช้้ กลับไปใช้ อันที่ประกาศข้างบน ซึ่ง มาทั้งหมด
$Recordset1 = mysql_query($strSQL, $Myconnect) or die(mysql_error());
?>
<!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=utf-8" />
<link rel="stylesheet" href="topmenu.css" type="text/css" />
<title>seeall_user</title>
</head>
<body background="bg.jpg" >
<!-- ?php require('topmenu.css'); ประกาศ stylesheet ประกาศแบบข้างบนนะครับ tag <link > ? -->
<center><br />
<table width="1229" height="152" border="0">
<tr><td width="1223" height="135" border="0"><center><img src="GSB_Logo.png" width="452" height="158" /></center></td>
</tr></table>
<table width="1254" height="31" border="0">
<tr><td width="705" height="25" >
<font color="#FFFFFF">
<form action=" " method="post" autocomplete="on">
<div id="headBottom">
<div id="topmenu">
<ul>
<li><a href="index_user.php"><span>หน้าแรก</span></a>
<a href="Account Summary.php"><span>เพิ่มบัญชีลูกค้า</span></a>
<a href="edit account.php"><span>แก้ไขบัญชีลูกค้า</span></a>
<a href="search_user.php"><span>ค้นหาแฟ้มงาน</span></a>
<a href="seeall_user.php"><span>ดูแฟ้มงานทั้งหมด</span></a>
<a href="contact.php"><span>แก้ไขข้อมูลส่วนตัว</span></a>
</li>
</ul>
</div>
<div class="bttnCheck"></div>
</div>
</form>
</font>
<div align="right" size="16">ยินดีต้อนรับ:<font color="#6633CC"><? echo $_SESSION["user"];?></font> <a href="login.php">Logout</a></div></td>
</tr>
</table>
<table width="1234" border="0">
<tr><td height="407" bgcolor="#FFFFFF">
<table width="1245" border="0">
<tr><td height="407" align="center" valign="top" bgcolor="#FFFFFF"><center>
<legend align="left" class="style1"><u><br /><font color="#333333" size="+1">แฟ้มบัญชีทั้งหมด</font></u></legend></center>
<center><br />
<table border="0">
<tr align="center" valign="middle" bgcolor="#4D4D4D">
<td width="166" bgcolor="#666699"><font color="#CCCCCC">ประเภทสินเชื่อ</font></td>
<td width="165" bgcolor="#666699"><font color="#CCCCCC">เลขที่บัญชี</font></td>
<td width="164" bgcolor="#666699"><font color="#CCCCCC">ชื่อ</font></td>
<td width="165" bgcolor="#666699"><font color="#CCCCCC">นามสกุล</font></td>
<td width="43" bgcolor="#666699"><font color="#CCCCCC">รายงาน</font></td>
</tr>
<?php
//do { ไม่ใช้ do เพราะ query ใหม่แล้ว ไม่ได้ fetch อะไรมา
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)){
?>
<tr align="center" valign="middle">
<td align="left" valign="middle" bgcolor="#CCCCCC"><?php echo $row_Recordset1['n_credit']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['id_credit']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['name']; ?></td>
<td bgcolor="#CCCCCC"><?php echo $row_Recordset1['lastname']; ?></td>
<td><a href="report.php?id_credit=<?php echo $row_Recordset1['id_credit']; ?>" >
<img src="report.png" width="37" height="28" /></a></td>
</tr>
<?php
}
?>
</table></center>
<br>Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?php
if($Prev_Page) echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
for($i=1; $i<=$Num_Pages; $i++){
echo ($i != $Page)? "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]" : "<b>$i</b>";
}
if($Page!=$Num_Pages) echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
?>
</td>
</tr></table></td>
</tr></table></td>
</tr></table>
<table width="1248" height="31" border="0"><tr><td width="705" height="1" bgcolor="#6666CC"></td></tr></table>
</center>
</body>
</html>
<?php
// mysql_free_result($Recordset1); ไม่ต้อง สั่งตรงนี้ พอสุดโปรแกรม มัน free ทุกอย่าง อัตโนมัติอยู่แล้่วครับ
?>
มีแก้หลายจุดนะครับ ลองอ่านแล้วทำความเข้าใจ ดูก่อนนะครับ ผมใส่ comment ไว้แล้วนะครับ
|
|
|
|
|
Date :
2014-11-17 12:46:57 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Chaidhanan
ขอบคุณมากๆ ค่ะ เดี๋ยวนำไปศึกษานะคะ
[
|
|
|
|
|
Date :
2014-11-17 13:01:20 |
By :
jibb |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|