Fallen
							
								หัวหน้าแก๊งเสียว 
								 
								
								พลังน้ำใจ:  162
								  ออฟไลน์
								กระทู้: 2,751
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 «  เมื่อ: 24 สิงหาคม 2018, 18:09:55 »  | 
								
								 | 
							  
							 
							
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							CherryX
							
								หัวหน้าแก๊งเสียว 
								 
								
								พลังน้ำใจ:  48
								  ออฟไลน์
								กระทู้: 2,052
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #1 เมื่อ: 24 สิงหาคม 2018, 22:08:37 »  | 
								
								 | 
							  
							 
							ขอบคุณคะ 
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							***ลายเซ็นสูงเกินขนาด 
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							del555
							
								สมุนแก๊งเสียว 
								 
								
								พลังน้ำใจ:  20
								  ออฟไลน์
								กระทู้: 912
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #2 เมื่อ: 24 สิงหาคม 2018, 23:51:20 »  | 
								
								 | 
							  
							 
							
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							sputtaro
							
								สมุนแก๊งเสียว 
								 
								
								พลังน้ำใจ:  139
								  ออฟไลน์
								กระทู้: 910
								
								 
								
								
								
								
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #3 เมื่อ: 25 สิงหาคม 2018, 00:19:19 »  | 
								
								 | 
							  
							 
							ลองแทนที่ echo '<pre>'; print_r($data);'</pre>'; ด้วยส่วนที่ดึงมาจาก database คือตั้งแต่ <table> ลงไปจนถึง </table>
 
  ส่วนคลิ๊กที่ page number (รวมทั้ง next และ last ) แล้วจะได้ข้อมูลของหน้านั้นๆหรือไม่ ผมไม่แน่ใจนะครับ  ถ้าไม่ได้ ลองเช็คค่า $_REQUEST['p'] รวมทั้งคำสั่ง select ดูนะครับ เพราะ select แบบนี้มันจะเลือกมา 20 เสมอ แต่มันขาด offset ไป
  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
									« แก้ไขครั้งสุดท้าย: 25 สิงหาคม 2018, 00:26:21 โดย sputtaro »
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							HurricaneSalmon
							
								Newbie 
								 
								
								พลังน้ำใจ:  1
								  ออฟไลน์
								กระทู้: 80
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #4 เมื่อ: 25 สิงหาคม 2018, 01:08:12 »  | 
								
								 | 
							  
							 
							ขอบคุณครั    
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							Fallen
							
								หัวหน้าแก๊งเสียว 
								 
								
								พลังน้ำใจ:  162
								  ออฟไลน์
								กระทู้: 2,751
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #5 เมื่อ: 25 สิงหาคม 2018, 07:20:06 »  | 
								
								 | 
							  
							 
							ลองแทนที่ echo '<pre>'; print_r($data);'</pre>'; ด้วยส่วนที่ดึงมาจาก database คือตั้งแต่ <table> ลงไปจนถึง </table>
 
  ส่วนคลิ๊กที่ page number (รวมทั้ง next และ last ) แล้วจะได้ข้อมูลของหน้านั้นๆหรือไม่ ผมไม่แน่ใจนะครับ  ถ้าไม่ได้ ลองเช็คค่า $_REQUEST['p'] รวมทั้งคำสั่ง select ดูนะครับ เพราะ select แบบนี้มันจะเลือกมา 20 เสมอ แต่มันขาด offset ไป
 
     page number ไม่ทำงานครับ เป็นเพราะโค๊ดที่เอามาแทน(ส่วนที่ดึงจาก databse) ไม่มีส่วนไหน เกียวข้องกับ $perpage ของ array เดิมหรือเปล่าครับ? เพราะตัด  print_r($data); ออกไปแล้ว ต้องทำอย่างไร ถึงจะเอา $perpage มารวมใน  โค๊ดส่วนที่ดึงจาก database ครับ (ผมเอา limit 20 ออกเพื่อตัดผลที่อาจกระทบกับโค๊ด)  
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
									« แก้ไขครั้งสุดท้าย: 25 สิงหาคม 2018, 07:42:31 โดย Fallen »
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							Fallen
							
								หัวหน้าแก๊งเสียว 
								 
								
								พลังน้ำใจ:  162
								  ออฟไลน์
								กระทู้: 2,751
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #6 เมื่อ: 25 สิงหาคม 2018, 07:29:21 »  | 
								
								 | 
							  
							 
							เอาโค๊ดมาแปะเผื่อใครอยากจะใช้ หรือ ทดสอบครับ index.php<?php include_once("config.php"); $result = mysqli_query($mysqli, "SELECT * FROM member ORDER BY id DESC");?> <?php require_once dirname(__FILE__) . '/Pagination.class.php'; $records = 200; $link = 'index.php?p='; $current = $_REQUEST['p'] ? $_REQUEST['p'] : 1; $perpage = 5; for ($i = ((($current-1)*$perpage)+1);  $i <= $current*$perpage; $i++) { $data[$i] = $i * 1001;} $pager = new Pagination($link, $records, $current, $perpage); try {$pager->render();
  	echo '<pre>';  	 	//print_r($data); 	echo "<table><tr><td>id</td><td>topic</td></tr>";  	while($res = mysqli_fetch_array($result)) { 		 		echo "<tr>"; 		echo "<td>".$res['id']."</td>";	 		echo "<td>".$res['topic']."</td>"; 		echo "</tr>";		 	}
  echo "</table>"; 	 	echo '</pre>'; 	 	$pager->render();} catch(Exception $e) { echo $e->getMessage(); } ?> ======================== <table><tr><td>id</td><td>topic</td></tr> <?php 	while($res = mysqli_fetch_array($result)) { 		 		echo "<tr>"; 		echo "<td>".$res['id']."</td>";	 		echo "<td>".$res['topic']."</td>"; 		echo "</tr>";		 	} ?> </table> Pagination.class.php<?php  /**  * Pagination.class.php  * Last Modify: May 2012  * By Narong Rammanee  */ class Pagination {	 	const PREV = '‹ Prev'; 	const FIRST = '« First'; 	const NEXT = 'Next ›'; 	const LAST = 'Last »'; 	public $totalPage; 	public $offset; 	private $link; 	private $records; 	private $curPage; 	private $perPage; 	private $scroll = 18; 	public function __construct($link, $records, $curPage, $perPage) 	{	   		$this->link    = $link;   		$this->records = $records;   		$this->curPage = $curPage;   		$this->perPage = $perPage;   		$this->totalPage = ($this->records) ? ceil($this->records / $this->perPage) : 0;   		$this->curPage = (!is_numeric($this->curPage)) ? 1 : $this->curPage; 		$this->offset   = ($this->totalPage <= 1) ? 0 : ($this->curPage - 1) * $this->perPage;	 	} 	public function render() 	{ 		if(!$html = self::compilePagination()) 			throw new Exception( 'Error obtaining Pagination!' ); 		 		echo $html; 	} 	private function compilePagination() 	{ 		$html = '<p class="css-pager">'; 		if($this->totalPage > 1 && $this->curPage > 1) { 			$html .= '<a href="' . $this->link . '1">' . self::FIRST . '</a>'; 		} 		if($this->totalPage > 1 && $this->curPage > 1) { 			$html .= '<a href="' . $this->link . ($this->curPage - 1) . '">' . self::PREV . '</a>'; 		} 		if($this->totalPage <= $this->scroll) { 			if($this->records <= $this->perPage) { 				$startPage = 1; 				$stopPage  = $this->totalPage; 			} else { 				$startPage = 1; 				$stopPage  = $this->totalPage; 			} 		} else { 			if($this->curPage < intval($this->scroll / 2) + 1) { 				$startPage = 1;  				$stopPage  = $this->scroll; 			} else { 				$startPage = $this->curPage - intval($this->scroll / 2); 				$stopPage  = $this->curPage + intval($this->scroll / 2); 			if($stopPage > $this->totalPage) $stopPage = $this->totalPage; 			} 		} 		if ($this->totalPage > 1) { 			for ($i = $startPage; $i <= $stopPage; $i++) { 				if ($i == $this->curPage) { 					$html .= '<span class="current_page">' . $i . '</span>'; 				} else { 					$html .= '<a href="'.$this->link.$i.'">' . $i . '</a>'; 				} 			} 		} 		if($this->curPage < $this->totalPage) { 			$html .= '<a href="' . $this->link . ($this->curPage + 1) . '">' . self::NEXT . '</a>'; 		} 		if($this->curPage < $this->totalPage) { 			$html .= '<a href="' . $this->link . $this->totalPage . '">' . self::LAST . '</a>'; 		} 		return $html.'</p>'; 	} }  css@CHARSET "UTF-8"; body { 	font-family: "Trebuchet MS", Tahoma, Verdana, Arial, Helvetica, sans-serif; 	font-size: 11px;  	color: #4f6b72; 	background: #E6EAE9 }
  .pager {   	padding: 5px 0 5px 0 } .css-pager a {  	text-decoration: none; 	color: #666; 	background: #F4F4F4; 	border: 1px solid #e0e0e0; 	padding: 2px 5px; 	margin: 2px; 	font-weight: 700; 	font-size: 11px } .css-pager a:hover {  	text-decoration: none; 	color: #fff; 	background: #0A85CB; 	border: 1px solid #3af; 	padding: 2px 5px; 	margin: 2px } .current_page { 	background-color: #0A85CB; 	border: 1px solid #3af; 	padding: 2px 5px; 	margin: 2px; 	color: #fff; 	font-weight: 700; 	font-size: 11px }
   
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							sputtaro
							
								สมุนแก๊งเสียว 
								 
								
								พลังน้ำใจ:  139
								  ออฟไลน์
								กระทู้: 910
								
								 
								
								
								
								
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #7 เมื่อ: 26 สิงหาคม 2018, 14:03:46 »  | 
								
								 | 
							  
							 
							ลองใช้ไฟล์ index.php นี้แทน แล้วทดสอบดูนะครับ
  <?php  include_once("config.php"); require_once dirname(__FILE__) . '/Pagination.class.php';
  $result= mysqli_query($mysqli, "SELECT id FROM member ORDER BY id DESC") ;  $records = mysqli_num_rows($result);
  $link = 'index.php?p=';
  if(isset($_GET['p'])){    $current = $_GET['p']; } else{    $current = 1; }
  $perpage = 5;
  $pager = new Pagination($link, $records, $current, $perpage);
  try {         $pager->render();    if((isset($current))&&($current>1)){          $start=$perpage*($current-1);    }    else{       $current=1;       $start=0;    }    $result2 = mysqli_query($mysqli, "SELECT id,topic FROM member ORDER BY id DESC LIMIT $start,$perpage") ;        echo '<pre>';       echo "<table><tr><td>id</td><td>topic</td></tr>";     while($res = mysqli_fetch_array($result2)) {              echo "<tr>";       echo "<td>".$res['id']."</td>";          echo "<td>".$res['topic']."</td>";       echo "</tr>";          }    echo "</table>";       echo '</pre>';        $pager->render(); } catch(Exception $e) {    echo $e->getMessage();  } ?> 
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
									« แก้ไขครั้งสุดท้าย: 26 สิงหาคม 2018, 14:30:29 โดย sputtaro »
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							Fallen
							
								หัวหน้าแก๊งเสียว 
								 
								
								พลังน้ำใจ:  162
								  ออฟไลน์
								กระทู้: 2,751
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #8 เมื่อ: 26 สิงหาคม 2018, 20:07:11 »  | 
								
								 | 
							  
							 
							
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							s_apt
							
								คนรักเสียว 
								 
								
								พลังน้ำใจ:  1
								  ออฟไลน์
								กระทู้: 105
								
								 
								
								
								
								
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #9 เมื่อ: 27 สิงหาคม 2018, 09:30:33 »  | 
								
								 | 
							  
							 
							ขอบคุณครับ    
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							Japam
							
								Newbie 
								 
								
								พลังน้ำใจ:  6
								  ออฟไลน์
								กระทู้: 69
								
								 
								
								
								
								
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #10 เมื่อ: 27 สิงหาคม 2018, 10:00:57 »  | 
								
								 | 
							  
							 
							ขอบคุณมากครับ ทั้งเจ้าของกระทู้ และท่านที่เข้ามาตอบ อธิบายละเอียดมากเลยครับ      
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							jommha
							
								คนรักเสียว 
								 
								
								พลังน้ำใจ:  2
								  ออฟไลน์
								กระทู้: 130
								
								 
								
								
								
								
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #11 เมื่อ: 27 สิงหาคม 2018, 14:39:44 »  | 
								
								 | 
							  
							 
							ขอบคุณครับ      
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							cloudsphere
							
								เจ้าพ่อบอร์ดเสียว 
								 
								
								พลังน้ำใจ:  229
								  ออฟไลน์
								กระทู้: 6,197
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #12 เมื่อ: 27 สิงหาคม 2018, 15:26:38 »  | 
								
								 | 
							  
							 
							ขอบคุณมากเลยครับ     
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							FatCat6
							
								ก๊วนเสียว 
								 
								
								พลังน้ำใจ:  9
								  ออฟไลน์
								กระทู้: 297
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #13 เมื่อ: 27 สิงหาคม 2018, 16:47:27 »  | 
								
								 | 
							  
							 
							ขอบคุณครับ     
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							dupai
							
								สมุนแก๊งเสียว 
								 
								
								พลังน้ำใจ:  28
								  ออฟไลน์
								กระทู้: 823
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #14 เมื่อ: 27 สิงหาคม 2018, 17:32:40 »  | 
								
								 | 
							  
							 
							Thank you 
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	
		
		
			
				
					
						
							somsaknus
							
								Newbie 
								 
								
								พลังน้ำใจ:  0
								  ออฟไลน์
								กระทู้: 60
								
								 
								
								
								
								
								 
								 
							 
						 | 
						
							
								  | 
								
									
									 « ตอบ #15 เมื่อ: 17 กันยายน 2018, 11:30:05 »  | 
								
								 | 
							  
							 
							ขอบคุณคับ     
						 | 
					 
					
						
							
								| 
								 | 
							 
								| 
								 | 
								
									 
									บันทึกการเข้า
								 | 
							  
							 
							
						 | 
					 
				 
			 |  
		 
	 | 
	 |