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,028

HOME > PHP > PHP Forum > แบ่งหน้า - ขอ code เกี่ยวกับการแบ่งหน้าพร้อมกับคำอธิบายที่เข้าใจง่ายๆหน่อยค่ะ



 

แบ่งหน้า - ขอ code เกี่ยวกับการแบ่งหน้าพร้อมกับคำอธิบายที่เข้าใจง่ายๆหน่อยค่ะ

 



Topic : 026124



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



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




ขอ code เกี่ยวกับการแบ่งหน้าพร้อมกับคำอธิบายที่เข้าใจง่ายๆหน่อยค่ะ
ขอบคุณค่ะ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-04-04 19:54:47 By : Kmay View : 4868 Reply : 25
 

 

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 = 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
 


 

No. 2



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



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


$Page = $_GET["Page"];

Page ที่อยู่ใน $_GET["Page"]; มาจากไหนค่ะ
หรือว่าตั้งเป็นอารัยก้อได้
Date : 2009-04-04 20:13:08 By : Kmay
 

 

No. 3



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

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

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

มาจาก ?Page=xx ครับผม
Date : 2009-04-04 20:29:14 By : webmaster
 


 

No. 4

Guest


ทำไมพอคลิกหน้าที่สอง หรือว่าหน้า next ไม่ขึ้นหน้าต่อไป

มีแต่ข้อความที่บอกว่า Total 0 Record : 1 Page : << Back [ 1 ] Next>>


ช่วยบอกหน่อยน่ะค่ะ พอดีว่าไม่ถนัดเรื่อง code ซักเท่าไหร่ ขอบคุณค่ะ
Date : 2009-12-23 15:14:19 By : ninee
 


 

No. 5



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



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


ไม่ยอมแบ่งหน้าให้ครับ ช่วยดูหน่อยครับ
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>


g
Date : 2011-05-13 15:59:33 By : buraratn
 


 

No. 6



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



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


sutthing ลองทำดู ไม่ยากคับ
Date : 2011-05-13 16:19:12 By : TEST_CODE
 


 

No. 7



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



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


<form action="" method="post">
<p align="center">&nbsp;</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">&#3594;&#3639;&#3656;&#3629;&#3618;&#3656;&#3629;</td>
<td width="240"><input name="subname" type="text" size="40" id="subname"/></td>
</tr>
<tr>
<td class="filedtable">&#3626;&#3606;&#3634;&#3609;&#3632;</td>
<td colspan="3">
<input name="status" type="radio" value="S" checked />
&#3651;&#3594;&#3657;&#3591;&#3634;&#3609;
<input name="status" type="radio" value="C" />
&#3618;&#3585;&#3648;&#3621;&#3636;&#3585;
<input name="status" type="radio" value="1" />&#3652;&#3617;&#3656;&#3651;&#3594;&#3657;&#3591;&#3634;&#3609;</td>
</tr>
<tr>
<td colspan="4">&nbsp;</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">&#3610;&#3619;&#3636;&#3625;&#3633;&#3607;&#3652;&#3615;&#3649;&#3609;&#3609;&#3595;&#3660;</td>
<td width="167" class="filedtable">&#3594;&#3639;&#3656;&#3629;&#3618;&#3656;&#3629;</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>&quot;ไม่มีรายการที่ท่านเลือก&quot;</b></center></font>";
} ?>
<? } ?> <br>
</form>
Date : 2011-05-13 16:24:54 By : pompam_mis
 


 

No. 8



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



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


ลองดู เพราะตัวนี้เป็นการเเบ่งหน้า ข้อมูลที่เกิดจากการค้นหา
Date : 2011-05-13 16:25:45 By : pompam_mis
 


 

No. 9



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



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


ขอลองดูแปป คับ
Date : 2011-05-13 16:33:18 By : buraratn
 


 

No. 10



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

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

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

ค้นหาแล้วแบ่งหน้า

Go to : PHP MySQL Search Record Paging/Pagination
Date : 2011-05-13 16:35:51 By : webmaster
 


 

No. 11



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



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


ลองแล้วครับ ไม่ได้ชักที ถ้าหน้ามา ข้อมูลก็หาย ข้อมูลมา หน้าก็ไม่แบ่งครับ
ไม่แน่ใจว่าต้องเอาโค้ดวางตรงไหนครับ
Date : 2011-05-13 17:15:08 By : buraratn
 


 

No. 12



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



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


ใช้โค้ดตัวไหนนิ
Date : 2011-05-13 17:23:45 By : pompam_mis
 


 

No. 13



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



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


พอดีว่าลองมาหลายโค้ดครับ
อันนี้ละครับ ปัจจุปัน
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>
g


ประวัติการแก้ไข
2011-05-13 17:29:04
Date : 2011-05-13 17:28:07 By : buraratn
 


 

No. 14



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



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


แปลงจากโค้ดแป๋มน่าจะได้ แค่เปลี่ยนแค่ฐานเท่านั้นเอง เพราะเงือนไขไม่น่าจะต่างกันมาก
Date : 2011-05-13 17:55:27 By : pompam_mis
 


 

No. 15



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



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


ลองดูก่อนครับ
Date : 2011-05-13 18:00:35 By : buraratn
 


 

No. 16



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



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


ไม่ไหวครับ แก้ไม่ถูกครับ ปวดหัวละครับ
Date : 2011-05-13 18:11:31 By : buraratn
 


 

No. 17



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



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


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
 


 

No. 18



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



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


ขอบคุณอีกครั้งครับ

แต่กดไปหน้า 2 หรือ next จะไม่มีข้อมูลครับ มีข้อมูลเฉพาะหน้าแรก ครับ
ds

ราคาห้อง กับค้นหาจะรีเส็จ เหมือนไม่ได้กรอกอะไรลงไปครับ
Date : 2011-05-13 20:17:14 By : buraratn
 


 

No. 19



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



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


ส่งตัวแปรไปด้วยคับ
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
 


 

No. 20



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



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


ได้แล้วครับ ขอบคุณครับ ดีใจน้ำตาจะไหล
Date : 2011-05-13 20:33:22 By : buraratn
 


 

No. 21



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



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


อย่างงี้ ต้องฉลอง
จบโปรเจค แล้วดิ
Date : 2011-05-13 20:50:34 By : TEST_CODE
 


 

No. 22



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



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


ยังไม่จบเลยครับ
ต้องเอาลิ้งเข้ากับ google map อีกครับ
เพื่อบอกที่อยู่และเส้นทางครับ


สงสัยต้องรบกวนผู้รู้อีกนานเลยครับ


ประวัติการแก้ไข
2011-05-13 21:45:08
Date : 2011-05-13 21:05:51 By : buraratn
 


 

No. 23

Guest


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 : ปลายฝน
 


 

No. 24

Guest


ผม ติดตรงนี้ครับ while($am=mysql_fetch_array($result))
Date : 2012-05-23 11:56:42 By : ปลายฝน
 


 

No. 25



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

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

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


ตามไปดูวิธีแบ่งหน้าที่นี่ก็ได้ครับ ง่ายมากๆๆ
ใช้ jquery https://www.thaicreate.com/php/forum/078810.html
Date : 2012-05-23 13:28:07 By : sakuraei
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : แบ่งหน้า - ขอ code เกี่ยวกับการแบ่งหน้าพร้อมกับคำอธิบายที่เข้าใจง่ายๆหน่อยค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่