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 ข้อมูล ผมใช้ตัวแปร $count++ ในการเรียงข้อมูล แต่ผมมีปัญหาตรงที่ว่าคลิกไปหน้าที่สอง



 

คือผมต้องการแบ่งหน้าเว็บครับผมมีข้อมูล อยู่หลายข้อมูล แต่ผมต้องการที่จะโชว์หน้าละ 10 ข้อมูล ผมใช้ตัวแปร $count++ ในการเรียงข้อมูล แต่ผมมีปัญหาตรงที่ว่าคลิกไปหน้าที่สอง

 



Topic : 059018



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



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




คือผมต้องการแบ่งหน้าเว็บครับผมมีข้อมมูลอยู่หลายข้อมูลแต่ผมต้องการที่จะโชว์หน้าละ10ข้อมูล
ผมใช้ตัวแปร $count++ ในการเรียงข้อมูล
แต่ผมมีปัญหาตรงที่ว่าคลิกไปหน้าที่สองลำดับกลับเริ่มนับ1-10ใหม่
คลิกไปหน้าที่สามลำดับก็กลับเริ่มนับ1-10ใหม่อีก
มันไม่ต่อเป็น11-20
21-30
ไม่ทราบว่าจะแก้ยังไงดี

Code (PHP)
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>แสดงจดหมาย</title>
</head>
<style type="text/css">
<!--
body,td,th {
	color: #000000;
}
body {
	background-color: #CCCCCC;
}
-->
</style><BODY><center>
  <p><img src="../Head/head.gif" width="1000" height="150"> </p>
   <form name="frmSearch" method="get" action="Search_1.php" target="_blank">
  <table width="500" border="0"align="center">
    <tr>
      <th>ค้นหาจดหมาย
        <input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_GET["txtKeyword"];?>">
      <input type="submit" value="Search" onClick="check2()"  >
	  <input type="button" value="Reset" OnClick="document.frmSearch.txtKeyword.value='';">	  </th>
    </tr>
  </table>
  
<script language="JavaScript">
function check2() {
if(document.frmSearch.txtKeyword.value=="") {
alert("กรุณากรอกข้อมูลที่ต้องการค้นหาด้วยครับ") ;
document.frmSearch.txtKeyword.focus() ;
return false ;
}
else
return true ;
}


</script>

</form>
  
  <p>
<?
include "connect.php";
$sql="select * from email order by id desc  ";
$result=mysql_db_query($dbname,$sql);
//$row=mysql_num_rows($result);
$Num_Rows = mysql_num_rows($result);
	
	
	$Per_Page = 10;   // 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;
	}

$sqlq="select * from email order by id desc limit $Page_Start , $Per_Page ";
$qresult=mysql_db_query($dbname,$sqlq);	

echo"<br>";
echo "
<a href='letter_view3.php'><font color='#0443AA'><b>[จัดการข้อมูลสมาชิก]</a></font> 
<a href='../webborad/ques_view.php'target='_blank'><font color='#0443AA'>[เว็บบอร์ด]</a></font></b>
<a href='statistic.php'target='_blank'><font color='#0443AA'><b>[ดูค่าสถิติจดหมายทั้งหมด]</a></font></b>
<a href=adminlogout.php><font color='#0443AA'><b>[ออกจากระบบ]</a></font></b><p>

<table width='800' border='0'><tr><td align='left'><b><font size='2' face='MS Sans Serif'color='#0443AA'>จำนวนข้อมูลทั้งหมด $Num_Rows: จากทั้งหมด $Num_Pages หน้า</td></b></font> <td align='right'><b><font size='2' face='MS Sans Serif'color='#0443AA'> หน้า $Page</td></b></font></tr></table>

<table width='800' border='1'>
<tr bgcolor='color='#0443AA'>
		<td width='50'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>ลำดับที่
</font></b></center></td>
		<td width='150'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>หมายเลขจดหมาย
</font></b></center></td>
		<td width='250'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>ชื่อผู้รับ
</font></b></center></td>
		<td width='150'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>ประเภทจดหมาย</font></b></center></td>
		<td width='200'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>วันที่ได้รับ
</font></b></center></td>
		<td width='100'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>สถานะ
</font></b></center></td>
		<td width='100'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>แก้ไข</font></b></center></td>
		<td width='100'><center><b><font size='2' face='MS Sans Serif'color='#FFFFFF'>ลบ</font></b></center></td></tr>";
?>
<?
while($record=mysql_fetch_array($qresult)) 
{		
		$count++;
		$id=$record[id];
		$iddoc=$record[iddoc];
		$name=$record[name];
		$lastname=$record[lastname];
		$doctype=$record[doctype];
		$day=$record[day];
		$mounth_app=$record[mont]; 
		$y_app=$record[year];
		//$time=$record[time1];
		$status=$record[status];
		
		echo "<tr bgcolor='#FFFFFF'>
		<td width='50'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$count</font></center></td>
		<td width='150'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$iddoc</font></center></td>
		<td width='250'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$name&nbsp; &nbsp;$lastname</font></center></td>
		<td width='150'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$doctype</font><center></td>
		<td width='200'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$day $mounth_app $y_app </font></center></td>
		<td width='100'><center><font size='2' face='MS Sans Serif'color='#0443AA'>$status</font></center></td>
		<TD width='100'><A HREF=\"letter_edit2.php?id_edit=$id\"onclick=\" return confirm('ยืนยันแก้ไข$name')\"><center>แก้ไข</A></TD></center> 
	<TD width='100'><A HREF=\"admin_type_delete.php?id_del=$id\"onclick=\" return confirm('ยืนยันลบ$name ออกจากระบบ')\"><center>ลบ</A></TD></center> 
	</tr>";
	}	

echo "</table>";
?>
<center>

<b><font size='3' face='MS Sans Serif'color='#0443AA'>หน้า </font> </b>:
	<?
	if($Prev_Page)
	{
		echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtKeyword=$_GET[txtKeyword]'><< Back</a>";
	}

	for($i=1; $i<=$Num_Pages; $i++){
		if($i != $Page)
		{
			echo "[ <a href='letter_view?Page=$i&txtKeyword=$_GET[txtKeyword]'>$i</a> ]";
		}
		else
		{
			echo "<b><font color='#0443AA'> $i</font> </b>";
		}
	}
	if($Page!=$Num_Pages)
	{
		echo " <a href ='letter_view?Page=$Next_Page&txtKeyword=$_GET[txtKeyword]'>Next>></a> ";
	}
	
?>
</center>
</center>
</center>
<br>
<br>
<h3 align="center" class="style1"><font color="#0000FF">[เพิ่มจดหมาย]</font></h3>
      <form  name="checkForm" method="POST" action="letter_save.php" onSubmit="return check()">
        <table width="512" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#99FFFF" size ="10">
          <tr>
            <td>ประเภทจดหมาย</td>
            <td><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
              <select name=doctype  >
                <option selected value="">เลือกประเภท</option>
                <option value="จดหมาย">จดหมาย</option>
                <option value="EMS">EMS</option>
                <option value="พัสดุ">พัสดุ</option>
              </select>
            </font></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td width="120">หมายเลข</td>
            <td width="382"><input name="iddoc" type="text" id="iddoc" size="30" maxlength="13"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>ชื่อ-นามสกุล</td>
            <td><label for="name"></label>
            <input name="name" type="text" id="name" size="25">
            -
            <label for="lastname"></label>
            <input name="lastname" type="text" id="lastname" size="25"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>วันที่ได้รับ</td>
			
            <td><font size="2" face="MS Sans Serif, Tahoma, sans-serif">
              <label for="year"></label>
            </font><? 
		          	$day =  date("d");
				  	$m_app = array ("ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
				  	$mounth_app = $m_app[date("n") - 1];
				  	$y_app = date("Y") + 543;
					
					//$H = date("H");  //คำนวนเวลา ชม.
				  	//$c_time = date("H:i");
					//$time = " เวลา$c_time น.";			
					?>
			
            <input   name="day"type="text"  id="day" value="<?= $day ?>"size="1" > 
            -
			<input   name="mont"type="text"  id="mont" value="<?= $mounth_app ?>" size="1"/> -
			<input   name="year"type="text"  id="year" value="<?= $y_app ?>" size="1"/> 
		    </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>สถานะ</td>
            <td><select name=status  >
                <option selected value="">เลือกสถานะ</option>
                <option value="ยังไม่รับ">ยังไม่รับ</option>
                <option value="รับแล้ว">รับแล้ว</option>
				<option value="ตีคืน">ตีคืน</option>
                </select></td>
          </tr>
</table>
<script language="javascript">
function check() {
if(document.checkForm.doctype.value=="") {
alert("กรุณาเลือกประเภท") ;
document.checkForm.doctype .focus() ;
return false ;
}
if(document.checkForm.iddoc.value=="") {
alert("กรุณาใสหมายเลขจดหมาย") ;
document.checkForm.iddoc .focus() ;
return false ;
}
if(document.checkForm.name.value=="") {
alert("กรุณาใส่ชื่อผู้รับ") ;
document.checkForm.doctype .focus() ;
return false ;
}
if(document.checkForm.lastname.value=="") {
alert("กรุณาใส่นามสกุลผู้รับ") ;
document.checkForm.doctype .focus() ;
return false ;
}
if(document.checkForm.status.value=="") {
alert("กรุณาเลือกสถานะ") ;
document.checkForm.doctype .focus() ;
return false ;
}

else 
return true ;
}
</script>
  			<div align="center"><br>
            <input name="submit" type="submit" value="ตกลง">
            <input name="reset" type="reset" value="ยกเลิก">
        </div>
    </form>
</BODY>
</HTML>



ช่วยเขียนให้ดูหน่อยว่าต้องแก้จุดไหนครับ



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-22 07:52:26 By : เด็กกระทิง View : 7441 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

เขียนให้แล้วครับ

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);

$Per_Page = 10;   // 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";
$objQuery  = mysql_query($strSQL);
?>
<table width="600" border="1">
  <tr>
  <th width="91"> <div align="center">No </div></th>
    <th width="91"> <div align="center">CustomerID </div></th>
    <th width="98"> <div align="center">Name </div></th>
    <th width="198"> <div align="center">Email </div></th>
    <th width="97"> <div align="center">CountryCode </div></th>
    <th width="59"> <div align="center">Budget </div></th>
    <th width="71"> <div align="center">Used </div></th>
  </tr>
<?
$no = 0;
if($Page > 1)
{
		$no = $Per_Page * $Page;
}
while($objResult = mysql_fetch_array($objQuery))
{
	$no++;
?>
  <tr>
  <td><div align="center"><?=$no;?></div></td>
    <td><div align="center"><?=$objResult["CustomerID"];?></div></td>
    <td><?=$objResult["Name"];?></td>
    <td><?=$objResult["Email"];?></td>
    <td><div align="center"><?=$objResult["CountryCode"];?></div></td>
    <td align="right"><?=$objResult["Budget"];?></td>
    <td align="right"><?=$objResult["Used"];?></td>
  </tr>
<?
}
?>
</table>

<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> ";
}
mysql_close($objConnect);
?>
</body>
</html>


Screenshot

PHP MySQL Pagination Auto Number






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-22 08:54:07 By : webmaster
 


 

No. 2

Guest


code อย่างที่ mr.win เขียนให้นั้นมันผิดนิดนึงครับ ต้องแก้ตรงสูตรคำนวณ $no ใหม่เป็นแบบนี้ถึงจะใช้ รันได้ครับ

แก้ตรงบนนทัดที่ :56 เป็น $no = ($Per_Page * $Page) - 10; ก็เป็นอันใช้ได้ครับ เพราะถ้าคิดกันตรงๆแล้ว

ถ้านำจำนวนแถวที่แสดงใน 1 หน้าคูรกับหน้ามันจะเริ่มเกินมา 10 ต้องลบออก 10 ครับ ถึงจะได้เลขที่รันถูกต้อง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-11 03:09:54 By : Chin Versicle NU.
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ลองดูบทความนี้ครับ



Go to : PHP MySQL Display Row No and Line Number แสดงเลขหน้ากำกับแถว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-06-11 06:33:15 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : คือผมต้องการแบ่งหน้าเว็บครับผมมีข้อมูล อยู่หลายข้อมูล แต่ผมต้องการที่จะโชว์หน้าละ 10 ข้อมูล ผมใช้ตัวแปร $count++ ในการเรียงข้อมูล แต่ผมมีปัญหาตรงที่ว่าคลิกไปหน้าที่สอง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่