  | 
              
	              
	                
  
    
	 
        สอบถาม : มีการเก็บข้อมูลการสั่งสินค้าใน database ในรูปแบบของ json แล้วจะแสดงข้อมูลในนั้นเป็น table ได้ยังไงครับ     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 คิวรี่ข้อมูล json ออกมา แล้วก็ลูป foreach เอาไปใช้ได้เลยนะครับ 
 
Code (PHP) 
<?php
$txtJson = '[{"USER_ID":"1","USER_NAME":"manussawin","USER_PASS":"2019","USER_FULLNAME":"Manussawin Sankam","USER_DEPT":"IT"}]';
$jsondata = json_decode($txtJson,true);
foreach($jsondata as $data){
echo $data['USER_ID']." ".$data['USER_FULLNAME'];
}
?>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-11-07 15:44:38 | 
                        By :
                            Manussawin | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 1 เขียนโดย : Manussawin เมื่อวันที่ 2019-11-07 15:44:38 
รายละเอียดของการตอบ ::
  แล้วถ้าตอนเก็บ เป็นประมาณนี้ละครับผม เหมือนต้องเข้าอีกชั้นนึงครับผม
 Code (PHP)
[{"Item":[{"ItemDescription":" Adult Ticket 0910","ItemCode":"1272","Quantity":"1","ItemCost":910,"TotalPaid":910,"TaxPaid":0,"AttendeeName":"","Barcode":"","IsExtraItem":"false","CouponCode":""},{"ItemDescription":" ...
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-11-07 16:13:06 | 
                        By :
                            คำบัน | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ตั้งค่า key มิติ 1 ถ้า key มีค่าที่เหมือนกันค่าจะเป็นสุดท้ายที่ foreach ลอง run ดู 
Code (PHP) 
<?php
$json = '{
    "book1": {
        "name": "Harry Potter and the Goblet of Fire",
        "author": "J. K. Rowling",
        "year": 2000,
        "genre": "Fantasy Fiction",
        "bestseller": true
    },
	"book2": {
        "name": "The Load of The Ring",
        "year": 300,
        "genre": "Fantasy Fiction",
        "bestseller": true
    }
}';
 
// Decode JSON data to PHP
$arr = json_decode($json, true);
print_r($arr);
echo "<hr>";
// Loop through the object
foreach($arr as $key=>$val){
    echo $key . "=>" . $val['name'] . "<br>";
}
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2019-11-07 16:59:32              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-11-07 16:56:01 | 
                        By :
                            Genesis™ | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 จริงๆ แล้วการทำงานแบบนี้ ไม่เหมาะที่จะเก็บ รูปแบบ json ลงใน database นะครับ 
 
สู้สร้าง ตารางมาเก็บข้อมูล จาก json โดยเฉพาะดีกว่า ทำเป็น FK อ้างอิงน่าจะดีกว่า                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-11-08 19:19:17 | 
                        By :
                            NewbiePHP | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |