  | 
              
	              
	                
  
    
	 
        แบ่งหน้า แล้ว รันตัวเลขลำดับ ข้างหน้า  แต่ หน้าแรก รับออกทุกแถวค่ะ     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 <html> 
<head> 
<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<style type="text/css"> 
<!-- 
body,td,th { 
	font-family: mS Sans Serif, microsoft Sans Serif, tahoma; 
	font-size: 9pt; 
} 
--> 
</style> 
 
<style type="text/css"> 
<!-- 
body,td,th { 
	font-family: mS Sans Serif, microsoft Sans Serif; 
	font-size: 11pt; 
}	 
    a:link  { TEXT-DECORATION: none; color: #3F7CB9} 
    a:visited {  text-decoration: none;color: #3399FF} 
    a:hover {  text-decoration: none;color: #FF9900} 
 
--> 
</style> 
 
</head> 
 
<body topmargin="0"> 
 
  <table width="500" border="0" cellspacing="1" cellpadding="3"> 
    
    
    <tr>  
      <td><table width="90%" border="0" cellspacing="0" cellpadding="5"> 
          <tr>  
            <td><table width="90%" border="0" cellspacing="0" cellpadding="0"> 
                <!--  <tr> 
                                                                  <td> </td> 
                                                                </tr>   --> 
                <?php 
	 
						include("db_conf.inc.php"); 
						include("compare_date.php"); 
						 
						$now_year=date("Y"); 
						$now_date=date("/m/d"); 
						 
						if($now_year>2500){ 
							$now_year=$now_year-543; 
						} 
						 
						$now_date=$now_year.$now_date; 
								 
						mysql_connect($hostname,$user,$password); 
						include("charset.inc.php"); 
 
						 
									 
				?> 
              </table></td> 
          </tr> 
          <tr>  
            <!--                    <td>...........................</td>    --> 
          </tr> 
          <tr>  
            <td height="20"> 
			<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
                <?php 
							echo  "<br>";		 
						//mysql_connect($hostname,$user,$password); 
						 
							$sql = "select * from viannews where newsstyle='1'  and  status='1'  "; 
						$db_query = mysql_db_query($dbname, $sql)  or die ("sql ไม่ได้ "); 
						 
						$num_rows = mysql_num_rows($db_query); 
						 
						 
						$ii=1; 
							$Per_Page = 3;   // 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_rows =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; 
} 
 
 
		 
						$i=1; 
						$j=1; 
						//if($num_rows>0){   
						 
						 
						if($Page > 1) 
{ 
	$i = ($Per_Page * ($Page-1)) + 1;  
} 
				 
$sql .= " order by postdate desc ,id desc LIMIT $Page_Start , $Per_Page"; 
	$db_query = mysql_db_query($dbname, $sql)  or die ("sql ไม่ได้ "); 
						 
 
 
						if($num_rows>0){   
							//echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><img src=\"pict49/app_banner01-1.jpg\" width=\"250\" height=\"30\"></div></td></tr>"; 
							echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><font size=\"3\"  face=\"Ms Sans Serif\" color=\"#CC0000\">+ + ฝ่ายบริหารทั่วไป</br></br></font></div></td></tr>"; 
						}		 
						 
						 
						 
						 
						 
				 
					while($i<$num_rows){  	// อ่านข้อมูลแต่ละเรกคอร์ด			 
							$result = mysql_fetch_array($db_query); 
							$nheader = $result[nheader]; 
							$booknumber = $result[booknumber]; 
							$nfile1 = $result[nfile1]; 
							$nfile2 = $result[nfile2]; 
							$nfile3 = $result[nfile3]; 
							$nfile4 = $result[nfile4]; 
							$nlink1 = $result[nlink1]; 
							$nlink2 = $result[nlink2]; 
							$nlink3 = $result[nlink3]; 
							$postdate = $result[postdate]; 
							$optionshow = $result[optionshow]; 
 
							$countfile=0; 
							$countlink=0; 
							$str_tmp=""; 
 
							if($nfile1!=""){ 
								$countfile++; 
							} 
							if($nfile2!=""){ 
								$countfile++; 
							} 
							if($nfile3!=""){ 
								$countfile++; 
							} 
							if($nfile4!=""){ 
								$countfile++; 
							} 
 
							if($countfile>1){ 
								$runfile=1; 
							} 
							else{ 
								$runfile=""; 
							} 
 
							if($nlink1!=""){ 
								$countlink++; 
							} 
							if($nlink2!=""){ 
								$countlink++; 
							} 
							if($nlink3!=""){ 
								$countlink++; 
							} 
 
							if($countlink>1){ 
								$runlink=1; 
							} 
							else{ 
								$runlink=""; 
							} 
						 
														 
					echo "<tr >"; 
								 
							 
								 
								echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\"  color=\"#CC0000\">$i</font></div>"; 
									 
									echo "<td valign=\"top\"><font size=\"3\"><div align=\"left\">$nheader  </div></font>"; 
									echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\"  color=\"#CC0000\">$booknumber</font></div>"; 
									 
									if($nfile1!=""){									 
									echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\"  color=\"#CC0000\"><a href=\"ocn_news/file/$nfile1\" target=\"_blank\"><font size=\"3\" color=\"#0066FF\">รายละเอียด $runfile </font></a></td>"; 
									$str_tmp=" | "; 
									$runfile++; 
								} 
								if($nlink1!=""){ 
									echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\"  color=\"#CC0000\">$str_tmp <a href=\"$nlink1\" target=\"_blank\"><font size=\"2\" color=\"#0066FF\">รายละเอียดเพิ่มเติม $runlink</font></a></td>"; 
									$runlink++; 
									$str_tmp=" | "; 
								} 
														 
								$tmp_caldate=calDate(seperateDate($postdate),seperateDate($now_date)); 
								if($tmp_caldate<=7){ 
									echo " <td valign=\"top\"><div align=\"left\"><font size=\"3\"  color=\"#CC0000\"><img src=\"img/i_new.gif\" width=\"30\" height=\"10\"></td> ";    
									 
						} 
						 
						 
						 
						 
						 
						 
								 
						 
								 
								echo "</div></td>"; 
							echo "</tr>"; 
							 
							 
							$i++; 
							 
						} 
						//echo  "<br>"; 
					//2	mysql_close(); 
									 
					?> 
              </table></td> 
          </tr> 
        </table></td> 
    </tr> 
<!--    <tr>  
      <td> </td> 
    </tr> --> 
  </table> 
 
 
 
 
<br> 
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page : 
<?php 
if($Prev_Page) 
{ 
	echo " <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Prev_Page'><< Back</a> "; 
} 
 
for($a=1; $a<=$Num_Pages; $a++){ 
	if($a != $Page) 
	{ 
		echo "[ <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$a'>$a</a> ]"; 
	} 
	else 
	{ 
		echo "<b> $a </b>"; 
	} 
} 
if($Page!=$Num_Pages) 
{ 
	echo " <a href ='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Next_Page'>Next>></a> "; 
} 
mysql_close(); 
?> 
</body> 
</html>                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-20 22:16:10 | 
                        By :
                            kabill | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองศึกษาดูนะครับ  
และคราวหน้าช่วย เอา tag code ครอบด้วยนะครับ อยู่เหนือ textarea  ขวามือนะครับ 
Code (PHP) 
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body,td,th {
font-family: mS Sans Serif, microsoft Sans Serif, tahoma;
font-size: 9pt;
}
-->
</style>
<style type="text/css">
<!--
body,td,th {
font-family: mS Sans Serif, microsoft Sans Serif;
font-size: 11pt;
}	
a:link { TEXT-DECORATION: none; color: #3F7CB9}
a:visited { text-decoration: none;color: #3399FF}
a:hover { text-decoration: none;color: #FF9900}
-->
</style>
</head>
<body topmargin="0">
<table width="500" border="0" cellspacing="1" cellpadding="3">
<tr><td>
	<table width="90%" border="0" cellspacing="0" cellpadding="5">
	<tr><td>
		<!--  tag table ข้างล่างนี้ สร้างมาเพื่ออะไรครับ -->
		<table width="90%" border="0" cellspacing="0" cellpadding="0">
<!-- <tr>
<td> </td>
</tr> -->
<?php
include("db_conf.inc.php");
include("compare_date.php");
$now_year=date("Y");
$now_date=date("/m/d");
if($now_year>2500){
	$now_year=$now_year-543;
}
$now_date=$now_year.$now_date;
mysql_connect($hostname,$user,$password);
include("charset.inc.php");
?>
		</table></td></tr>
		<tr> 
		<!-- <td>...........................</td> -->
		</tr>
		<tr><td height="20">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
echo "<br>"; // echo ทำไมครับ มันอยู่ใน tag table ไม่ได้มีประโยชน์อะไรเลย	
//mysql_connect($hostname,$user,$password);
/* 
$sql = "select * from viannews where newsstyle='1' and status='1' ";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
$num_rows = mysql_num_rows($db_query);
*/
// 3 บันทัดบน เปลือง bandwidth สำหรับการ transfer ข้อมูล เปลี่ยนเป็นข้างล่าง
$sql = "select count(*) from viannews where newsstyle='1' and status='1' ";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
list($num_rows) = mysql_fetch_row($db_query); mysql_free_result($db_query);
$ii=1;
$Per_Page = 3; // Per Page
/*
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
*/ 
// กำหนดค่า $Page ข้างบน จะมี warning ถ้าเรียกใช้ครั้งแรก
$Page = isset($_GET['Page'])? $_GET['Page'] : 1;
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = $Page * $Per_Page - $Per_Page; // หลักคณิตศาสตร์ คอมฯ ทำตามความสำคัญของ operator ที่สำคัญก่อน ไม่ต้องใส่วงเล็บก็ได้
/*
if($num_rows<=$Per_Page)
{
$num_rows =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;
}
*/
// ข้างบนมันอ้อมไปหรือเปล่าครับ
$Num_Page = ceil( $num_rows / $Per_Page); // หาจำนวนเพจทั้งหมด
$i=1;
$j=1;
//if($num_rows>0){ 
if($Page > 1)
{
$i = ($Per_Page * ($Page-1)) + 1; 
}
// statement สำหรับ หา จำนวน record และ นำมาใช้งาน แยกกันชัดเจน เพราะใช้งานคนละอย่าง
$sql = "select * from viannews where newsstyle='1' and status='1' "; 
$sql .= " order by postdate desc ,id desc LIMIT $Page_Start , $Per_Page";
$db_query = mysql_db_query($dbname, $sql) or die ("sql ไม่ได้ ");
if($num_rows>0){ 
//echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><img src=\"pict49/app_banner01-1.jpg\" width=\"250\" height=\"30\"></div></td></tr>";
echo "<tr><td colspan=\"2\" valign=\"top\"><div align=\"left\"><font size=\"3\" face=\"Ms Sans Serif\" color=\"#CC0000\">+ + ฝ่ายบริหารทั่วไป</br></br></font></div></td></tr>";
}
//while($i<$num_rows){ // อ่านข้อมูลแต่ละเรกคอร์ด	
// while ข้างบน ที่ทำให้ แสดง จำนวนบันทัดทั้งหมด เพราะ $num_rows เป็นค่า จำนวนทั้งหมดของ การคิวรี่ ครั่งแรก
//$result = mysql_fetch_array($db_query) 
// ไม่จำเป็นต้องใช้ fetch_array เพราะไม่ได้มีการอ้าง แบบ ลำดับที่ของ element ใช้ชื่อในการอ้าง
while( $result = mysql_fetch_assoc($db_query)){ // แบบนี้ชัดเจนว่าได้ result ตามต้องการแน่นอน ไม่มีบันทัดเกิน
	//$nheader = $result[nheader];  แบบนี้ไม่ควรเขียน ควรมี single quote ครอบขื่อ ฟีลด์ด้วย
	// มันไม่ error แต่มันมี warning ทำให้เครื่องทำงานหนักเพิ่มขึ้น
/*
	$nheader = $result['nheader']; 
	$booknumber = $result['booknumber'];
	$nfile1 = $result['nfile1'];
	$nfile2 = $result['nfile2'];
	$nfile3 = $result['nfile3'];
	$nfile4 = $result['nfile4'];
	$nlink1 = $result['nlink1'];
	$nlink2 = $result['nlink2'];
	$nlink3 = $result['nlink3'];
	$postdate = $result['postdate'];
	$optionshow = $result['optionshow'];
*/
	// ข้างบนเขียนยาวไป แต่ก็ถือว่าอ่านแล้วเข้าใจ แต่ลองลดรูปนะครับ
	extract($result); // คำสั่งนี้ทำแทนคำสั่งข้างบนนะครับ
	// สำหรับข้างล่างต่อไป ลองแก้เอาเองนะครับ
	
	$countfile=0;
	$countlink=0;
	$str_tmp="";
	
	if($nfile1!="") $countfile++; 
	if($nfile2!="") $countfile++;
	if($nfile3!="") $countfile++;
	if($nfile4!="") $countfile++;
	
	if($countfile>1) $runfile=1; else $runfile="";
	if($nlink1!="") $countlink++; 
	if($nlink2!="") $countlink++;
	if($nlink3!="") $countlink++;
	
	if($countlink>1) $runlink=1; else $runlink="";
	echo "<tr >";
	echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$i</font></div>";
	echo "<td valign=\"top\"><font size=\"3\"><div align=\"left\">$nheader </div></font>";
	echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$booknumber</font></div>";
	
	if($nfile1!=""){	
		echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><a href=\"ocn_news/file/$nfile1\" target=\"_blank\"><font size=\"3\" color=\"#0066FF\">รายละเอียด $runfile </font></a></td>";
		$str_tmp=" | ";
		$runfile++;
	}
	if($nlink1!=""){
		echo "<td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\">$str_tmp <a href=\"$nlink1\" target=\"_blank\"><font size=\"2\" color=\"#0066FF\">รายละเอียดเพิ่มเติม $runlink</font></a></td>";
		$runlink++;
		$str_tmp=" | ";
	}
	
	$tmp_caldate=calDate(seperateDate($postdate),seperateDate($now_date));
	if($tmp_caldate<=7){
		echo " <td valign=\"top\"><div align=\"left\"><font size=\"3\" color=\"#CC0000\"><img src=\"img/i_new.gif\" width=\"30\" height=\"10\"></td> "; 
	}
	
	echo "</div></td>";
	echo "</tr>";
	
	$i++;
}
//echo "<br>";
//2	mysql_close();
?>
</table></td>
</tr>
</table></td>
</tr>
<!-- <tr> 
<td> </td>
</tr> -->
</table>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Prev_Page'><< Back</a> ";
}
for($a=1; $a<=$Num_Pages; $a++){
if($a != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$a'>$a</a> ]";
}
else
{
echo "<b> $a </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?ppage=main&Page=$Next_Page'>Next>></a> ";
}
mysql_close();
?>
</body>
</html>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-21 08:51:13 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ขอบคุณ   คุณChaidhanan   มากๆค๊าาา  แล้วจะทบทวนทีละบรรทัดค๊าา                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2014-10-21 08:57:30 | 
                        By :
                            kabill | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |