|  | 
	                
  
    | 
	 
        รบกวนช่วยดูเรื่องการแบ่งหน้าหน่อยค่ะ แบ่งได้แต่ เอ๋อ ค่ะ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | คือ code แบ่งหน้าเราแบ่งได้แล้วแต่ทว่าทำไมเรากำหนด limit ไว้ 20 แต่พอเปิดหน้า 2 หน้า 3... มันไม่เท่ากับ 20 ค่ะ รบกวนช่วยดูหน่อยนะค่ะ พอดีมันเป็นการแบ่งหน้าใน array เฉพาะตารางสุดท้ายค่ะ
 
 code ค่ะ
 Code (PHP)
 
 <?php
include "function.php";
include "connect.php";
//for ($i=1; $i<=count($statusordertype); $i++) {
$bgcolor = array("#0576FF","#FFCC33","#FC7A28","#FC2868","#28FCBD");
$limit = 20;
$loop = count($statusordertype);
for ($i=1; $i<=$loop; $i++) {
	${'page'.$i} = (isset($_GET['page'.$i]) and $_GET['page'.$i] != "")? intval($_GET['page'.$i]) : 1;
	${'start'.$i} = ((${'page'.$i}-1)*$limit);
	${'end'.$i} = (${'start'.$i}+$limit)-1;
	$send = "";
	
	$sql="select * from tb_order where status_order='$i' order by date_order desc ";
	$count = mysql_num_rows(mysql_db_query($dbname,$sql));
	
	echo "
	<center><table width='90%' border='0' >
	<tr bgcolor='" . $bgcolor[$i] . "'>
			<td width='2%'><center><font color='000000' font size='2' face='MS Sans Serif'>ลำดับ</font></center></td>
			<td width='3%'><center><font color='000000' font size='2' face='MS Sans Serif'>วันที่</font></center></td>
			<td width='3%'><center><font color=000000' font size='2' face='MS Sans Serif'>เวลา</font></center></td>
			<td width='3%'><center><font color='000000' font size='2' face='MS Sans Serif'>สาขา</font></center></td>
			<td width='5%'><center><font color='000000' font size='2' face='MS Sans Serif'>ชื่อผู้สั่ง</font></center></td>
			<td width='5%'><center><font color='000000' font size='2' face='MS Sans Serif'>จัดส่งโดย</font></center></td>
			<td width='5%'><center><font color='000000' font size='2' face='MS Sans Serif'>ผู้รับเรื่อง</font></center></td>
			<td width='3%'><center><font color='000000' font size='2' face='MS Sans Serif'>สถานะ</font></center></td>
			<td width='3%'><center><font color='000000' font size='2' face='MS Sans Serif'>เพิ่มเติม</font></center></td>
			<td width='3%'><center><font color='000000' font size='2' face='MS Sans Serif'>ต้องการ</font></center></td>
	</tr><br>";
	//echo $sql . " limit " . ${'start'.$i} . "," . ${'end'.$i};
	$result = mysql_db_query($dbname, $sql . " limit " . ${'start'.$i} . "," . ${'end'.$i});
	$no=${'start'.$i}+1; 
	while($r=mysql_fetch_array($result)) {
		$id_order=$r[id_order];
		$branch_order=$r[branch_order];
		$name_order=$r[name_order];
		$memo_name_order=$r[memo_name_order];
		$sent_by_order=$r[sent_by_order];
		$recipients_order=$r[recipients_order];
		$memo_recipients_order=$r[memo_recipients_order];
		$report_order1=$r[report_order1];
		//$number_order=$r[number_order];
		$status_order=$r[status_order];
		$date_order=displaydate($r[date_order]);
		$time_order=$r[time_order];
	
		echo "	
			<tr bgcolor='#FFFFFF'>
			<td width='2%' ><center><font size='2' face='MS Sane Serif'>$no</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'>$date_order</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'>$time_order</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'> $branchordertype[$branch_order]</font></center></td>
			<td width='5%' ><center><font size='2' face='MS Sane Serif'> $nameordertype[$name_order]</font></center></td>
			<td width=5%' ><center><font size='2' face='MS Sane Serif'> $sentbyordertype[$sent_by_order]</font></center></td>
			<td width='5%' ><center><font size='2' face='MS Sane Serif'> $recipientsordertype[$recipients_order]</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'> $statusordertype[$status_order]</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'><a href=\"more_order.php?id_more=$id_order\">รายละเอียด</font></center></td>
			<td width='3%' ><center><font size='2' face='MS Sane Serif'><a href=\"edit_order.php?id_edit=$id_order\">แก้ไข</a></font></center></td>
		</tr>";
		$no++;
	}
		for ($j=1; $j<=$loop; $j++) {
			if($j != $i){
				$send .= "page".$j."=".${'page'.$j}."&";
			}
		}
		echo "	
		<tr>
			<td colspan=10>" . page($i, ${'page'.$i}, $limit, $count, $send) . "</td>
		</tr>";
}
//}
?>
?>
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2009-09-24 15:25:26 | By :
                          gummezaka | View :
                          949 | Reply :
                          14 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ต่อ file funtion นะค่ะ 
 Code (PHP)
 
 <?php
}
function page($n, $page, $limit, $count, $send=NULL, $target="_self", $range = 4){
	$output = "";
	$total = ceil($count/$limit);
	$navi_start = $page-$range;
	$navi_end = $page+$range;
	
	$send .= (!empty($send))? "" : NULL;
		
	if($navi_start <= 0) $navi_start = 1;
	if($navi_end >= $total) $navi_end = $total;
	
	if($total>1){
	$output .=  "\n<p id=\"pagesplit\"> Page : ";
		if($page>1){
			$navi_back = $page-1;
			if($page > 2) $output .=  "<a href=\"?" . $send . "page".$n."=1\" target=\"" . $target . "\">«</a> ";
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $navi_back . "\" target=\"" . $target . "\">‹</a> ";
		}
		for($i = $navi_start; $i <= $navi_end; $i++){
			if($i == $page)
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $i . "\" target=\"" . $target . "\"><strong>$i</strong></a> ";
			else
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $i . "\" target=\"" . $target . "\">$i</a> ";
		}
		if($page < $total){
			$navi_next = $page+1;
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $navi_next . "\" target=\"" . $target . "\">›</a> ";
			if(($page+1) < $total)
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $total . "\" target=\"" . $target . "\">»</a>";
		}
		if($navi_start>$navi_end) 
			$output .=  "<a href=\"?" . $send . "page".$n."=" . $page . "\" target=\"" . $target . "\"><strong>$page</strong></a> ";
		$output .=  "</p>";
	}
	return $output;
}
?>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 15:29:51 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  เอาแว้ว ... ม่ายมีครายมาจ๋วยเยยอ่ะ แงแง งอแงเลยเรา 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 16:14:31 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองดูโค๊ดผมไหม 
 Code (PHP)
 
 <?php
function show_page($result_total,$max_page,$where)	// function(จำนวนข้อมูลทั้งหมด, จำนวนเลขหน้า , เงือนใข)
{			
	global $limit;
	global $j;
	global $page;
	
	$sum_page = ceil($result_total/$limit);  				
	$next =  ceil($sum_page/$max_page);				
	$mod =  $sum_page%$max_page;					
	
	$k=1;
	for($n=0;$n<=$sum_page;$n=$n+$max_page)
		{			
			$arr_page[$k]=$n;								
			$k++;			
		}
				
	if($mod!=0)
		{		
			$arr_page[$k]=$sum_page;		
		}
		
			
	if($arr_page[$j+1]>1)
		{
	
		for($i=$arr_page[$j];$i<=($arr_page[$j+1]-1);$i++)
			{		
				$p=$i+1;	
				
				if($j>1 && $i==$arr_page[$j])	
					{					
						echo "<a href='?start=".$limit*($p-2)."&page=".($p-1)."&j=".($j-1)."&".$where."'>< กลับ</a>  " ; 	
					}	
				
					if($p==$page)			
						{		
							echo "<font color='#000000'><b>$p</b></font>";
						}
					else		
						{									
							echo "<a href='?start=".$limit*($p-1)."&page=$p&j=".$j."&".$where."'><font color='#FF0000'>$p</font></a>" ;
						}	
					
				if($i < $arr_page[$j+1]-1){echo" | ";}				
															
				if($j<$next && $i ==($arr_page[$j+1]-1))
					{				
						echo "  <a href='?start=".($limit*$p)."&page=".($p+1)."&j=".($j+1)."&".$where."'>ถัดไป ></a>" ;
					}			
				}
			}	
		else echo "<font color='#000000'><b>1</b></font>";					
}
	if(!isset($start){$start=0;}		
	if(!isset($page){$page=1;}	 
	if(!isset($j){$j=1;}
	
		$maxpage=10;		 // คือจำนวนตัวเลขหน้า จาก ตย. จะเป็น   1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10   ถัดไป >
		$limit = 20;
		
	$sql_num = "select  *  from  table ";
	$query_num = mysql_query($sql_num);			
	$num_rows = mysql_num_rows($query_num);   // จำนวนทั้งหมด
	
	$sql_show = "select  *  from  table LIMIT $start,$limit";
	$query_show  = mysql_query($sql_show);			
	while($fetch_array = mysql_fetch_array($query_show)){	
	
		// แสดงข้อมูล
	}
echo show_page($num_rows,$maxpage,"");  // เรียกใช้ฟังก์ชั่น  (จำนวนข้อมูลทั้งหมด, จำนวนเลขหน้า , เงือนใข)  ตรงเงือนไขถ้าไม่มีก้อไม่ต้องใส่ ถ้ามีใส่แบบนี้ ตย. show_page($num_rows,$maxpage,"search=$search");
?>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 16:29:35 | By :
                            heng |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | แก้ไขนิดหน่อย ลืมปิด ) อีก1วง if(!isset($start)){$start = 0;}
 if(!isset($page)){$page=1;}
 if(!isset($j)){$j=1;}
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 16:46:08 | By :
                            heng |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ... 
 เดวทำใหม่
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 16:47:00 | By :
                            danya |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ยังมะด้ายเลยค่ะ แปววว ...  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 16:55:14 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แว้วอ่ะ ดุน เมื่อกี้มี่ลืม รีเฟรส แปวว  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 17:12:30 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  มิน่าหละ ถึงฟันหลอ เพราะลืม รีเฟรช นี่เอง 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 17:36:26 | By :
                            deawx |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  แปววว ขำมั้ยอ่ะตาเดี่ยว ชิชิ ม่ายออนให้ถามแต่มาโพสเน็บ แงบๆๆ อย่าให้เจอ ตีก้นลาย 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 17:39:22 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 17:45:27 | By :
                            plakrim |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              |  ถามตรูไมแว้  มีเทพเจ้าให้ถามอยู่แล้วงิ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 19:49:35 | By :
                            deawx |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | นี่อีกคน...หายไปเยย งอลแว้ว  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 19:52:06 | By :
                            gummezaka |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | อ้าว สรุปว่าได้แล้วเหรอ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-09-24 20:28:19 | By :
                            danya |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 |  |