  | 
              
	              
	                
  
    
	 
        การ gen แบบนี้ มี limit ไหม ครับ ระบบ จะgen ไปถึงเท่าไหร่ ผมอยากให้ไม่มี limit ต้องทำอย่างไร     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                จากตัวอย่าง https://www.thaicreate.com/community/php-auto-generate-number-alt.html 
 
 
  
 
โค๊ดหน้าบันทึก ใบสั่งสินค้า พร้อม gen หมายเลข Order ปรับปรุงจาก ระบบ ตะกร้า ที่แจกครับ เลยไม่รู้ว่าระบบที่ผู้เขียน ได้เขียนขึ้น สามารถรันไปถึงจำนวนเท่าไหร่  
ตอนนี้รูปแบบ เป็นแบบนี้ ORDER-000031 //อยากรู้ว่า จำนวนที่รันมานี่จะรันถึงจำนวนเท่าไหร่ มีlimit หรือ ไม่มี limit ถ้ามี limit ทำอย่างไร ให้ run ไป อย่างไม่มี limit 
 
Code (PHP) 
if($_POST["action"]=="add")
{
// อ่าน OrderID
$strResultOrderID=select("orderid","where 1");
$strOrderID="ORDER-".substr("000000000$strResultOrderID[OrderID]", -6);
//อ่าน MemberID
$strMemberID=select("member","where 1 and Email='".$_SESSION["strEmail"]."'");
// Insert Order
$sql = "insert into cusorder (OrderNo,MemberID,Total,Date) Values ('$strOrderID','$strMemberID[MemberID]','$_POST[txtTotal]','".date("Y-m-d")."')";
$dbquery = mysql_query($sql);
								  
// Insert Detail
for($i=0;$i<=count($_SESSION["strProductID"]);$i++)
{
	$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"]["$i"]."' ");
	if($result)
	{
			$Proid=$_SESSION["strProductID"]["$i"];
			$Quanlity=$_SESSION["strQuanlity"]["$i"];
			$sql = "update product set Stock=Stock-$Quanlity where ProductID='$Proid'";
			$dbquery = mysql_query($sql);
				
			$sql = "insert into order_detail (OrderNo,ProductID,Quanlity) Values ('$strOrderID','".$_SESSION["strProductID"]["$i"]."','".$_SESSION["strQuanlity"]["$i"]."')";
			$dbquery = mysql_query($sql);
	}
}
// Update Order ตัวต่อไปให้เป็น 1
update("orderid","OrderID=OrderID+1","where 1");
	$_SESSION["strP"]="";
	$_SESSION["strProductID"]="";
	$_SESSION["strQuanlity"]="";
	session_write_close();
	//============  กระโดดไปหน้า ordercomplete.php
header("location:ordercomplete.php?OrderID=$strOrderID");
}
 
 
  Tag : PHP, HTML, CSS, Ajax, jQuery               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2017-06-01 16:01:01	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-06-01 15:57:53 | 
                      By :
                          sawmon | 
                      View :
                          989 | 
                      Reply :
                          7 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ดูค่า maximum ของ field type 
 
integer = ? 
big integer = ?                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-01 16:24:55 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ผมก็ไม่คล่องครับ ให้แนวได้ว่า 
 
ในการแยก id นั้น จาก SUBSTR(`id`, 6)  
//ถ้าเราแยก 4 หลักท้ายออกมาได้ ก็เอาไปเข้าเงื่อนไขเปรียบเทียบกับ 9999 
ถ้าค่า SUBSTR ที่ได้ไม่เท่ากับ 9999 ก็ให้มันดำเนินการรันเลขต่อไป 
แต่ถ้าเมื่อไรค่าที่ SUBSTR ออกมามีค่า 9999 ให้ทำการเพิ่มค่าที่ต้องการ จาก 1 เป็น 2 แล้วก็นับ 0000 ใหม่ 
เงื่อนไขตรงนี้ก็อยู่ที่ WHERE SUBSTR(`id`, 1, 4) = DATE_FORMAT(NOW(), '%Y')  
ยิ่งมองว่าถ้าไม่สนใจเรื่อง ปี ค.ศ. เปลี่ยนแค่ 1 เป็น 2 ไปเรื่อยๆ ไม่น่่าจะยากนะ 
 
จาก coed ตัวอย่างการ gen auto number ถ้าว่างๆ ผมว่าก็น่าจะทำได้ ถ้าว่างๆ จากงานประจำก็น่าลองทำดูไม่น่ายาก 
ตอนนี้ก็มีแนวคิดครับ ถ้าได้ลองเล่น Auto Number ก็น่าจะเขียนออก 
 
คุณก็ลองพยายามดูก่อนครับ ไม่แน่นะอาจจะมีคนใจดีกว่าผมเขียน code ออกมาเลยก็ได้                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-02 11:52:20 | 
                        By :
                            apisitp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Insert into tablename 
(x,y, field1,field2) 
Select x + if(y=9999,1,0), if(y=9999,1,y+1),var1,var2 
From (select x, y from tablename order by x desc,y desc limit 1) as tmp 
 
ปล ยังไม่ไดตรวจสอบกรณี ยังไม่มีข้อมูลลองคิดเอาหน่อย                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-02 15:34:19 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |