แบ่งหน้า - ขอ code เกี่ยวกับการแบ่งหน้าพร้อมกับคำอธิบายที่เข้าใจง่ายๆหน่อยค่ะ
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 = 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";
$objQuery = mysql_query($strSQL);
?>
<table width="600" border="1">
<tr>
<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>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<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>
Ref : PHP MySQL List Record Paging
Date :
2009-04-04 20:02:32
By :
webmaster
$Page = $_GET["Page"];
Page ที่อยู่ใน $_GET["Page"]; มาจากไหนค่ะ
หรือว่าตั้งเป็นอารัยก้อได้
Date :
2009-04-04 20:13:08
By :
Kmay
มาจาก ?Page=xx ครับผม
Date :
2009-04-04 20:29:14
By :
webmaster
ทำไมพอคลิกหน้าที่สอง หรือว่าหน้า next ไม่ขึ้นหน้าต่อไป
มีแต่ข้อความที่บอกว่า Total 0 Record : 1 Page : << Back [ 1 ] Next>>
ช่วยบอกหน่อยน่ะค่ะ พอดีว่าไม่ถนัดเรื่อง code ซักเท่าไหร่ ขอบคุณค่ะ
Date :
2009-12-23 15:14:19
By :
ninee
ไม่ยอมแบ่งหน้าให้ครับ ช่วยดูหน่อยครับ
Code (PHP)
<html>
<head>
<title>ค้นหา</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
function get_search (p, t){
var p = $("#price").val();
var t = $("#txtKeyword").val();
if(p.length==0 && t.length==0){
alert('โปรดเลือกราคาหรือชื่อหอพักที่ต้องการค้นหา');
}
}
</script>
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="get_search (price, txtKeyword)">
<table width="641" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="631">ราคาห้องพัก
<select name="price" id="price">
<option value="">- เลือกราคา -</option>
<option value="1" <? if($price==1){?>selected<? }?>>น้อยกว่า1000</option>
<option value="2" <? if($price==2){?>selected<? }?>>1001-1500</option>
<option value="3" <? if($price==3){?>selected<? }?>>1501-2000</option>
<option value="4" <? if($price==4){?>selected<? }?>>2001-2500</option>
<option value="5" <? if($price==5){?>selected<? }?>>2501-3000</option>
<option value="6" <? if($price==6){?>selected<? }?>>มากกว่า 3000</option>
</select>
ค้นหา
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<? @include("connect.php");
$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 id_prd ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<?
if($_REQUEST['price']!=''){
$price = $_REQUEST['price'];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 ";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 ";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 ";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 ";
break;
case 6:
$where = " WHERE price_prd > 3000 ";
break;
}
}
if($_REQUEST["txtKeyword"] != ""){
$detail = $_REQUEST["txtKeyword"];
$where = " WHERE (name_prd LIKE '%".$detail."%') ";
}
if($_REQUEST['price']!='' && $_REQUEST["txtKeyword"] != ""){
$price = $_REQUEST['price'];
$name_prd = $_REQUEST["txtKeyword"];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 OR name_prd LIKE '%".$name_prd."%' ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 6:
$where = " WHERE price_prd > 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
}
}
?>
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<th width="92"> <div align="center">รหัสหอพัก</div></th>
<th width="97"> <div align="center">ชื่อหอพัก </div></th>
<th width="140"> <div align="center">ประเภทหอพัก </div></th>
<th width="83"> <div align="center">ราคา</div></th>
<th width="110"> <div align="center">รูปภาพ </div></th>
<th width="170"> <div align="center">รายละเอียด</div></th>
</tr>
<?
if($price!='' || $txtKeyword!=''){
$strSQL = "SELECT * FROM tb_product ";
$strSQL .= " LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type";
$strSQL .= " $where";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="50"><div align="center"><?=$objResult["id_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_type"];?></div></td>
<td><div align="center"><?=$objResult["price_prd"];?></div></td>
<td align="right"><div align="center"><img src="photo/<?=$objResult["photo_prd"];?>" width="30" /></div>
</td> <td>[ <A HREF='search_view.php?id_prd=<?=$objResult["id_prd"];?>'>แสดงรายละเอียด </A>] </div></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>
Date :
2011-05-13 15:59:33
By :
buraratn
sutthing ลองทำดู ไม่ยากคับ
Date :
2011-05-13 16:19:12
By :
TEST_CODE
<form action="" method="post">
<p align="center"> </p>
<table width="793" border="0" align="center" class="border">
<tr>
<td colspan="4" class="headtable"></td>
</tr>
<tr>
<td width="192" class="filedtable"></td>
<td width="240"><input name="name" type="text" size="40" id="name"/></td>
<td width="196" class="filedtable">ชื่อย่อ</td>
<td width="240"><input name="subname" type="text" size="40" id="subname"/></td>
</tr>
<tr>
<td class="filedtable">สถานะ</td>
<td colspan="3">
<input name="status" type="radio" value="S" checked />
ใช้งาน
<input name="status" type="radio" value="C" />
ยกเลิก
<input name="status" type="radio" value="1" />ไม่ใช้งาน</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td height="28" colspan="4"><div align="center">
<input name="search" type="submit" class="button" value="ค้นหา" />
<input name="cancal" type="reset" class="button" id="cancal" value="ยกเลิก" />
<input name="add" type="button" class="button" id="add" value="เพิ่ม" onClick="window.location='500100175A.php?action=addfin'">
</div></td>
</tr>
</table>
<? include "connect.php";
conndb();
mysql_select_db($dbname);
$s=$_REQUEST['search'];
$mode=$_GET['action'];
$name=$_REQUEST['name'];
$subname=$_REQUEST['subname'];
$status=$_REQUEST['status'];
if((!empty($s)) || ($mode=='viewsearch')|| (!empty($name)) || (!empty($subname)) || (!empty($status))){
$sql="select *from dlr_fin_mst WHERE FM_FIN_NM like '%$name%' AND FM_FIN_INI_NM like '%$subname%' AND FM_DISPLAY like '%$status%'";
$query = mysql_query($sql)or die (mysql_error());
$num =mysql_num_rows($query);
$per_page = 2;
$page = $_GET['page'];
if(!$_GET['page']) {
$page=1;
}
$totalpage=ceil($num/$per_page);
$prev_page = $page-1;
$next_page = $page+1;
$page_start = (($per_page*$page)-$per_page);
if($num<=$per_page) {
$num_pages =1;
} else if(($num % $per_page)==0) {
$num_pages =($num/$per_page);
} else{
$num_pages =($num/$per_page)+1;
$num_pages = (int)$num_pages;
}
$sql .=" LIMIT $page_start,$per_page";
$query = mysql_query($sql);
if($num >0){ ?>
<table width="864" border="0" align="center" class="border">
<tr>
<td width="59" class="filedtable">#</td>
<td width="524" class="filedtable">บริษัทไฟแนนซ์</td>
<td width="167" class="filedtable">ชื่อย่อ</td>
<td width="110" class="filedtable">สถานะ</td>
</tr>
<?
$k=0;
while($row= mysql_fetch_array($query)){
$k++;
$name1=$row['FM_FIN_NM'];
$id1=$row['FM_FIN_CD'];
$ini1=$row['FM_FIN_INI_NM'];
$display=$row['FM_DISPLAY'];
?>
<tr style="background-color:#CCFF99">
<td class="body"><div align="center"><? echo $k ?></div></td>
<td class="body"><b><? echo "<a href='500100177V.php?id=$id1&action=viewfin'>$name1</a>"?></b></td>
<td class="body"><? echo $ini1 ?></td>
<td class="body"><?
if ($display=="S"){ echo "ใช้งาน"; }
if ($display=="C"){ echo "ยกเลิก"; }
if ($display=="1"){ echo "ไม่ใช้งาน"; }
if ($display=="0"){ echo "ลบ"; }?> </td> </tr>
<? } ?>
<span class="body">มีรายการทั้งหมดจำนวน <?=$num;?> รายการ : </span>
<? if($prev_page>1){
echo "<span class=\"body\"> | <a href='$_SERVER[SCRIPT_NAME]?page=$prev_page&name=$name&subname=$subname&status=$status'>หน้าก่อนนี้</a> | </span>";
}
for($i=1;$i<=$num_pages;$i++){
if($i != $page)
{
echo "<span class=\"body\"> | <a href='$_SERVER[SCRIPT_NAME]?page=$i&name=$name&subname=$subname&status=$status'>$i</a> | </span>";
}else {
echo "<span class=\"body\"><b>$i</b></span>";
}
}
if($page!=$num_pages) {
echo "<span class=\"body\"> | <a href ='$_SERVER[SCRIPT_NAME]?page=$next_page&name=$name&subname=$subname&status=$status'>หน้าต่อไป</a> | </span>";
}
?>
</table>
<? }else{
echo "<br>";
echo "<font color=#FF0000><center><b>"ไม่มีรายการที่ท่านเลือก"</b></center></font>";
} ?>
<? } ?> <br>
</form>
Date :
2011-05-13 16:24:54
By :
pompam_mis
ลองดู เพราะตัวนี้เป็นการเเบ่งหน้า ข้อมูลที่เกิดจากการค้นหา
Date :
2011-05-13 16:25:45
By :
pompam_mis
ขอลองดูแปป คับ
Date :
2011-05-13 16:33:18
By :
buraratn
ลองแล้วครับ ไม่ได้ชักที ถ้าหน้ามา ข้อมูลก็หาย ข้อมูลมา หน้าก็ไม่แบ่งครับ
ไม่แน่ใจว่าต้องเอาโค้ดวางตรงไหนครับ
Date :
2011-05-13 17:15:08
By :
buraratn
ใช้โค้ดตัวไหนนิ
Date :
2011-05-13 17:23:45
By :
pompam_mis
พอดีว่าลองมาหลายโค้ดครับ
อันนี้ละครับ ปัจจุปัน
Code (PHP)
<html>
<head>
<title>ค้นหา</title>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
function get_search (p, t){
var p = $("#price").val();
var t = $("#txtKeyword").val();
if(p.length==0 && t.length==0){
alert('โปรดเลือกราคาหรือชื่อหอพักที่ต้องการค้นหา');
}
}
</script>
</head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="get_search (price, txtKeyword)">
<table width="641" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="631">ราคาห้องพัก
<select name="price" id="price">
<option value="">- เลือกราคา -</option>
<option value="1" <? if($price==1){?>selected<? }?>>น้อยกว่า1000</option>
<option value="2" <? if($price==2){?>selected<? }?>>1001-1500</option>
<option value="3" <? if($price==3){?>selected<? }?>>1501-2000</option>
<option value="4" <? if($price==4){?>selected<? }?>>2001-2500</option>
<option value="5" <? if($price==5){?>selected<? }?>>2501-3000</option>
<option value="6" <? if($price==6){?>selected<? }?>>มากกว่า 3000</option>
</select>
ค้นหา
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<? @include("connect.php");
$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 id_prd ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<?
if($_REQUEST['price']!=''){
$price = $_REQUEST['price'];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 ";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 ";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 ";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 ";
break;
case 6:
$where = " WHERE price_prd > 3000 ";
break;
}
}
if($_REQUEST["txtKeyword"] != ""){
$detail = $_REQUEST["txtKeyword"];
$where = " WHERE (name_prd LIKE '%".$detail."%') ";
}
if($_REQUEST['price']!='' && $_REQUEST["txtKeyword"] != ""){
$price = $_REQUEST['price'];
$name_prd = $_REQUEST["txtKeyword"];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 OR name_prd LIKE '%".$name_prd."%' ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 6:
$where = " WHERE price_prd > 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
}
}
?>
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<th width="92"> <div align="center">รหัสหอพัก</div></th>
<th width="97"> <div align="center">ชื่อหอพัก </div></th>
<th width="140"> <div align="center">ประเภทหอพัก </div></th>
<th width="83"> <div align="center">ราคา</div></th>
<th width="110"> <div align="center">รูปภาพ </div></th>
<th width="170"> <div align="center">รายละเอียด</div></th>
</tr>
<?
if($price!='' || $txtKeyword!=''){
$strSQL = "SELECT * FROM tb_product ";
$strSQL .= " LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type";
$strSQL .= " $where";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td height="50"><div align="center"><?=$objResult["id_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_type"];?></div></td>
<td><div align="center"><?=$objResult["price_prd"];?></div></td>
<td align="right"><div align="center"><img src="photo/<?=$objResult["photo_prd"];?>" width="30" /></div>
</td> <td>[ <A HREF='search_view.php?id_prd=<?=$objResult["id_prd"];?>'>แสดงรายละเอียด </A>] </div></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>
ประวัติการแก้ไข 2011-05-13 17:29:04
Date :
2011-05-13 17:28:07
By :
buraratn
แปลงจากโค้ดแป๋มน่าจะได้ แค่เปลี่ยนแค่ฐานเท่านั้นเอง เพราะเงือนไขไม่น่าจะต่างกันมาก
Date :
2011-05-13 17:55:27
By :
pompam_mis
ลองดูก่อนครับ
Date :
2011-05-13 18:00:35
By :
buraratn
ไม่ไหวครับ แก้ไม่ถูกครับ ปวดหัวละครับ
Date :
2011-05-13 18:11:31
By :
buraratn
Code (PHP)
<html>
<head>
<title>ค้นหา</title>
<style type="text/css">
th {font-family:sans-serif;
font-size:12px;
}
</style>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
function get_search (p, t){
var p = $("#price").val();
var t = $("#txtKeyword").val();
if(p.length==0 && t.length==0){
alert('โปรดเลือกราคาหรือชื่อหอพักที่ต้องการค้นหา');
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"></head>
<body>
<form name="frmSearch" method="post" action="<?=$_SERVER['PHP_SELF']?>" onSubmit="get_search (price, txtKeyword)">
<table width="641" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="631">ราคาห้องพัก
<select name="price" id="price">
<option value="">- เลือกราคา -</option>
<option value="1" <? if($price==1){?>selected<? }?>>น้อยกว่า1000</option>
<option value="2" <? if($price==2){?>selected<? }?>>1001-1500</option>
<option value="3" <? if($price==3){?>selected<? }?>>1501-2000</option>
<option value="4" <? if($price==4){?>selected<? }?>>2001-2500</option>
<option value="5" <? if($price==5){?>selected<? }?>>2501-3000</option>
<option value="6" <? if($price==6){?>selected<? }?>>มากกว่า 3000</option>
</select>
ค้นหา
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<? @include("connect.php"); ?>
<?
if($_REQUEST['price']!=''){
$price = $_REQUEST['price'];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 ";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 ";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 ";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 ";
break;
case 6:
$where = " WHERE price_prd > 3000 ";
break;
}
}
if($_REQUEST["txtKeyword"] != ""){
$detail = $_REQUEST["txtKeyword"];
$where = " WHERE (name_prd LIKE '%".$detail."%') ";
}
if($_REQUEST['price']!='' && $_REQUEST["txtKeyword"] != ""){
$price = $_REQUEST['price'];
$name_prd = $_REQUEST["txtKeyword"];
switch($price){
case 1:
$where = " WHERE price_prd < 1000 OR name_prd LIKE '%".$name_prd."%' ";
break;
case 2:
$where = " WHERE price_prd BETWEEN 1001 AND 1500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 3:
$where = " WHERE price_prd BETWEEN 1501 AND 2000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 4:
$where = " WHERE price_prd BETWEEN 2001 AND 2500 OR name_prd LIKE '%".$name_prd."%'";
break;
case 5:
$where = " WHERE price_prd BETWEEN 2501 AND 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
case 6:
$where = " WHERE price_prd > 3000 OR name_prd LIKE '%".$name_prd."%'";
break;
}
}
?>
<table border="0" cellpadding="0" cellspacing="1">
<tr>
<th width="92" bgcolor="#FBFCE4"> <div align="center">รหัสหอพัก</div></th>
<th width="97" bgcolor="#FBFCE4"> <div align="center">ชื่อหอพัก </div></th>
<th width="140" bgcolor="#FBFCE4"> <div align="center">ประเภทหอพัก </div></th>
<th width="83" bgcolor="#FBFCE4"> <div align="center">ราคา</div></th>
<th width="110" bgcolor="#FBFCE4"> <div align="center">รูปภาพ </div></th>
<th width="170" bgcolor="#FBFCE4"> <div align="center">รายละเอียด</div></th>
</tr>
<?
if($price!='' || $txtKeyword!=''){
$strSQL = "SELECT * FROM tb_product ";
$strSQL .= " LEFT JOIN tb_type ON tb_product .ref_id_type = tb_type.id_type";
$strSQL .= " $where";
$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 id_prd ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
$bg = 1;
while($objResult = mysql_fetch_array($objQuery)) {$bg++;
if($bg%2==0){
$bgr = '#FFF';
}else{
$bgr = '#EBEBEB';
}
?>
<tr bgcolor="<?=$bgr?>">
<td height="50"><div align="center"><?=$objResult["id_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_prd"];?></div></td>
<td><div align="center"><?=$objResult["name_type"];?></div></td>
<td><div align="center"><?=$objResult["price_prd"];?></div></td>
<td align="right"><div align="center"><img src="photo/<?=$objResult["photo_prd"];?>" width="40" /></div></td>
<td>[ <A HREF='search_view.php?id_prd=<?=$objResult["id_prd"];?>'>แสดงรายละเอียด </A>] </div></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>
Date :
2011-05-13 19:55:03
By :
test
ขอบคุณอีกครั้งครับ
แต่กดไปหน้า 2 หรือ next จะไม่มีข้อมูลครับ มีข้อมูลเฉพาะหน้าแรก ครับ
ราคาห้อง กับค้นหาจะรีเส็จ เหมือนไม่ได้กรอกอะไรลงไปครับ
Date :
2011-05-13 20:17:14
By :
buraratn
ส่งตัวแปรไปด้วยคับ
Code (PHP)
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&price=$_REQUEST[price]&txtKeyword=$_REQUEST[txtKeyword]'>Next>></a> ";
}
//mysql_close($objConnect);
?>
Date :
2011-05-13 20:24:49
By :
TEST_CODE
ได้แล้วครับ ขอบคุณครับ ดีใจน้ำตาจะไหล
Date :
2011-05-13 20:33:22
By :
buraratn
อย่างงี้ ต้องฉลอง
จบโปรเจค แล้วดิ
Date :
2011-05-13 20:50:34
By :
TEST_CODE
ยังไม่จบเลยครับ
ต้องเอาลิ้งเข้ากับ google map อีกครับ
เพื่อบอกที่อยู่และเส้นทางครับ
สงสัยต้องรบกวนผู้รู้อีกนานเลยครับ
ประวัติการแก้ไข 2011-05-13 21:45:08
Date :
2011-05-13 21:05:51
By :
buraratn
Code (PHP)
<!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>Untitled Document</title>
<style type="text/css">
.style1 { font-weight: bold;
color: #FFFFFF;
}
.style3 {color: #FFFFFF}
</style>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","admin") or die("Error Connect to Database");
$objDB = mysql_select_db("kongthon");
$strSQL = "SELECT * FROM news ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5; // 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 news ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
<table width="733" border="1" cellspacing="1">
<tr>
<th width="40"> <div align="center">แก้ไข</div></th>
<th width="41"> <div align="center">ลบ</div></th>
<th width="53"> <div align="center">รหัสข่าว</div></th>
<th width="257"> <div align="center">หัวข้อข่าว</div></th>
<th width="72"> <div align="center">เพิ่มเมื่อ</div></th>
<th width="63"> <div align="center">แก้ไขล่าสุด</div></th>
<th width="53"> <div align="center">ผู้ลงข่าว</div></th>
</tr>
<?
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{ ?>
?>
<tr align="center" valign="middle">
<td height="37"><a href="editnews.php?id_n=<?=$objResult [id_n];?>">Edit</a> <a href="deletenews.php?id_n=<?=$objResult [id_n];?>"> </td>
<td> <a href="deletenews.php? id_n=<?=$objResult [id_n];?>">Delete</a></td>
<td><?=$objResult [id_n];?></td>
<td><?=$objResult [h_n];?></td>
<td><?=$objResult [d_n];?></td>
<td><?=$objResult [df_n];?></td>
<td><?=$objResult [n_n];?></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);
//https://www.thaicreate.com/php/forum/026124.html
?>
</body>
</html>
Date :
2012-05-23 10:45:49
By :
ปลายฝน
ผม ติดตรงนี้ครับ while($am=mysql_fetch_array($result))
Date :
2012-05-23 11:56:42
By :
ปลายฝน
Load balance : Server 00