Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > รบกวนช่วยดูการแบ่งหน้าให้หน่อยค่ะ อยากกำหนดข้อมูลให้ขึ้นแค่ 10 ข้อมูล



 

รบกวนช่วยดูการแบ่งหน้าให้หน่อยค่ะ อยากกำหนดข้อมูลให้ขึ้นแค่ 10 ข้อมูล

 



Topic : 112603



โพสกระทู้ ( 27 )
บทความ ( 0 )



สถานะออฟไลน์




อยากกำหนดให้ข้อมูลขึ้นแค่ 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>&nbsp;<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







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-11-17 00:45:59 By : jibb View : 724 Reply : 5
 

 

No. 1



โพสกระทู้ ( 361 )
บทความ ( 1 )



สถานะออฟไลน์


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
 


 

No. 2



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



สถานะออฟไลน์


069. $Per_Page = 2; // Per Page ถูกกำหนดให้แสดง 2 รายการ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 07:19:11 By : Chaidhanan
 

 

No. 3



โพสกระทู้ ( 27 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : Chaidhanan เมื่อวันที่ 2014-11-17 07:19:11
รายละเอียดของการตอบ ::
คือในโค้ดมันขึ้น11 รายการเลยค่ะ ทั้งๆที่ตั้งว่า $Per_Page = 2; // Per Page ช่วยดูให้หน่อยนะคะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 11:46:19 By : jibb
 


 

No. 4



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



สถานะออฟไลน์


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>&nbsp;<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
 


 

No. 5



โพสกระทู้ ( 27 )
บทความ ( 0 )



สถานะออฟไลน์


Chaidhanan
ขอบคุณมากๆ ค่ะ เดี๋ยวนำไปศึกษานะคะ
[
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-11-17 13:01:20 By : jibb
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนช่วยดูการแบ่งหน้าให้หน่อยค่ะ อยากกำหนดข้อมูลให้ขึ้นแค่ 10 ข้อมูล
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่