|  |  | 
          
            | การ sort ข้อมูลกรณีที่่มีหลายหน้าทำไงครับ พอผมกดให้เรียงข้อมูลข้อมูลจะเรียงเฉพาะหน้าแรกที่กดพอกดไปยังหน้า 2 หรือหน้าต่างๆข้อมูลที่เรียงไว้จะไม่ต่อกันอะครับ Code (PHP)
 
 $Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5;
$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;
}
$strSort = $_GET["sort"];
if($strSort == "")
{
	$strSort = "DormitoryID";
}
$strOrder = $_GET["order"];
if($strOrder == "")
{
	$strOrder = "ASC";
}
$strSQL .=" order  by ".$strSort." ".$strOrder." LIMIT {$Page_Start} , {$Per_Page}";
$objQuery  = mysql_query($strSQL);
$strNewOrder = $strOrder == 'DESC' ? 'ASC' : 'DESC';
?>
	<br>
<table width="93%" class="data1">  <tr class="data1"> 
  		<th  width="9%" height="45" background="img/1.jpg"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=type&order=<?=$strNewOrder?>">ประเภท</th>
		<th background="img/1.jpg" width="41%">รูปห้อง</th>
        <th background="img/1.jpg" width="11%"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=name&order=<?=$strNewOrder?>">ชื่อ</th>
        <th background="img/1.jpg" width="9%"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=Provinc&order=<?=$strNewOrder?>">ที่อยู่</th>
        <th background="img/1.jpg" width="14%"><a href="<?=$_SERVER["PHP_SELF"];?>?sort=Price&order=<?=$strNewOrder?>">ราคา</th>
        <th background="img/1.jpg" width="16%">อ่านต่อ</th>
 </tr>
  <?php
  while($objResult = mysql_fetch_array($objQuery))
  {
  ?>
  
  <tr>
  
    <form action="" method="post">
     
    <td class="data1" width="9%" ><center> <?php echo $objResult["type"];?></center></td>
	<td class="data1" width="41%" >
    <center><a onClick="javascript:void window.open('images/<?php echo $objResult["picture"];?>','','width=500,height=300,toolbar=0,menubar=0,location=0,status=Y,scrollbars=1,resizable=1,left=0,top=0');return false;" href="image/<?php echo $objResult["picture"];?>"><img src="images/<?php echo $objResult["picture"];?>" width="190" height="120"></a></center>
    <center><label style="font-size:11px;"><a href="#">คลิกที่รูปภาพเพิ่อขยาย</a></label></center></td>  
    <td class="data1" width="11%" ><?php echo $objResult["name"];?></td>
    <td class="data1" width="9%" ><?php echo $objResult["Amphur"];?> <?php echo $objResult["Province"];?></td>
     <td class="data1" width="14%"><?=$objResult['Price'];?>-<?=$objResult['HPrice'];?>บาท</td>
    <td class="data1"  width="16%" >
      <a href="detail_dormitory1.php?DormitoryID=<?php echo $objResult["DormitoryID"];?>">เพิ่มเติม</a></td>
    
    </form>
    </tr>
  <?php
  }
  ?>
</table>
<br><br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?php
if($Prev_Page)
{
	echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'&sort=$strSort'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
	if($i != $Page)
	{
		echo "[ <a href='$_SERVER[PHP_SELF]?Page=$i&sort=$strSort'>$i</a> ]";
	}
	else
	{
		echo "<b> $i </b>";
	}
}
if($Page!=$Num_Pages)
{
	echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&sort=$strSort'>Next>></a> ";
}
mysql_close();
?>
 
 
 Tag : PHP
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2016-07-09 18:52:29 | By :
                          mylastgame | View :
                          839 | Reply :
                          2 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |