  | 
              
	              
	                
  
    
	 
        การแบ่งหน้า +access คือผมลอง ใช้ code ตัวอย่างจากในบทเรียนไปลองน่ะครับ แต่ error ตอนติดต่อกับ DB     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
               คือผมลอง ใช้ code ตัวอย่างจากในบทเรียนไปลองน่ะครับ แต่ error ตอนติดต่อกับ DB คิดว่าน่าจะมาจากตรงนี้ครับ คืออยากทราบว่า mysql กับ access ใช้คำสั่งเดียวกันได้มั้ยครับ ถ้าไม่ได้ต้องเปลี่ยนเป็นยังไงครับ 
$sql2="SELECT * FROM xxx ORDER BY Product_Name LIMIT $page_start, $per_page"; 
 
========= code ทั้งหมดคับ ========== 
include("ConAccess.inc"); 
		$sql="SELECT * FROM Product "; 
		$sql1="SELECT count(*) FROM Product"; 
		$execute=odbc_exec($connect, $sql) or die ("Can not connect to Database"); 
		$execute1=odbc_exec($connect, $sql1) or die ("Can not connect to Database"); 
		$countAll=odbc_result($execute1,1); 
		$countLow=odbc_result($execute, 1); 
		$fields=odbc_num_fields($execute);		 
		//set value 
		$per_page=2; 
		if(!$page) $page=1; 
		 
		$prev_page=$prev_page-1; 
		$next_page=$next_page+1; 
		 
		//$execute 
		$page_start = ($per_page*$page)-$per_page; 
		//$countAll==num_row 
		 
		if($countAll<=$per_page) $num_page=1; 
		else if (($countAll % $per_page)==0) $num_page=($countAll / $per_page); 
		else $num_page=($countAll / $per_page)+1; 
		 
		$num_page=(int)$num_page; 
		 
		if (($page > $num_page) || ($page < 0)) 
			print "xxx"; 
		$sql2="SELECT * FROM Product ORDER BY Product_Name LIMIT $page_start, $per_page"; 
		$execute2=odbc_exec($connect, $sql2) or die ("sssssssss"); 
		 
?> 
<html> 
<head> 
<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"> 
</head> 
 
<body> 
<table width="580" border="0" cellspacing="0" cellpadding="0" align="left"> 
  <tr> 
    <td height="35" background="images/bg02.gif"><div align="center"><font color="#003399" size="+2"><b>รายการสินค้า</b></font></div></td> 
  </tr> 
  <tr> 
  	<td>จากทั้งหมด <?=$countAll?> รายการ</td> 
  </tr> 
  <tr> 
  	<td>		 
		<table width="560" border="0" bgcolor="#9999FF" align="left"><tr> 
		<td width="10"> </td> 
		<td width="175"><div align="center"><font color="#FFFFFF" size="+1"><?=odbc_field_name($execute2, 2);?></font></div></td> 
		<td width="175"><div align="center"><font color="#FFFFFF" size="+1"><?=odbc_field_name($execute2, 3);?></font></div></td> 
		<td width="50"><div align="center"><font color="#FFFFFF" size="+1">จำนวน</font></div></td> 
		<td width="70"><div align="center"><font color="#FFFFFF" size="+1">รายละเอียด</font></div></td> 
		</tr><tr><td colspan="5">		 
		<?  
		$j=1; 
		while(odbc_fetch_row($execute2,$j)) 
		{ 
		$name=odbc_result($execute2,2); 
		$model=odbc_result($execute2,3); 
		$count=odbc_result($execute2,8); 
		?> 
		<table width="580" border="0" bgcolor="#FFFFFF"> 
		<tr> 
		<td width="10"><?=$j?></td> 
		<td width="175"><? echo "$name"; ?></td> 
		<td width="175"><? echo "$model"; ?></td> 
		<td width="50"><div align="center"><? echo "$count"." หน่วย"; ?></div></td> 
		<td width="70"><a href="show.php" title="คลิ๊กเพื่อดูรายละเอียดของสินค้า">รายละเอียด</a></td> 
		</tr> 
		</table> 
		<? 
		$j++; 
		} 
		echo "rows,page== $countAll $num_page"; 
		//echo "$fields"."<br>"; 
		include("CloseAccess.inc"); 
		?> 
		</td> 
		</tr> 
		</table> 
  </tr> 
</table> 
 
</body> 
</html>
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          24 ธ.ค. 2547  16:35:38 | 
                      By :
                          Ken | 
                      View :
                          3349 | 
                      Reply :
                          5 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ดูในบทเรียนดีกว่าไหมครับ                        
               
               | 
             
            
              
			  			  
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            27 ธ.ค. 2547  09:48:22 | 
                        By :
                            @W_IN | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 LIMIT $page_start, $per_page"; 
ตรงนี้ ใช่ป่ะ  มีคน(จริงๆนะ) บอกว่า access ใช้ไม่ได้ฮ่ะ   
ยังติดเหมียนกัน..                          
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            26 มิ.ย. 2548  13:00:06 | 
                        By :
                            noname | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                Access ไม่มี LIMIT นะคับ ใช้ 
SELECT TOP (fieldname) FROM Table; คับ 
 
** TOP=LIMIT นั่นแหละคับ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            16 พ.ค. 2550  16:46:39 | 
                        By :
                            ทอย ดมจ 19 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                แก้ไขนิดนึง 
SELECT TOP fieldname FROM Table; คับ 
ไม่มีวงเล็บน่ะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            16 พ.ค. 2550  16:47:41 | 
                        By :
                            ทอย ดมจ 19 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
<html>
<head>
<title>ThaiCreate.Com PHP & Access Tutorial</title>
</head>
<body>
<?
$objConnect = odbc_connect("mydatabase","","") or die("Error Connect to Database");
$strSQL = "SELECT * FROM customer ORDER BY CustomerID ASC";
$objExec = odbc_exec($objConnect, $strSQL) or die ("Error Execute [".$strSQL."]");
$Num_Rows = 0;
while(odbc_fetch_row($objExec))$Num_Rows++; // Count Record
$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)+1;
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;
}
$Page_End = $Per_Page * $Page;
?>
<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>
<?
for($i=$Page_Start;$i<=$Page_End;$i++)
{
$objResult = odbc_fetch_array($objExec,$i);
?>
<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> ";
}
odbc_close($objConnect);
?>
</body>
</html>
 
 
Ref : PHP Microsoft Access List Record Paging (PHP ODBC)                        
               
               | 
             
            
              
			  			  
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-04-25 06:47:17 | 
                        By :
                            webmaster | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |