File "read_json.php"

Full Path: /home/analogde/www/Prog/MMM/Fusion/Table/read_json.php
File size: 2.88 KB
MIME-type: text/html
Charset: utf-8


<style>
      table, th, td {
        border: 1px solid #666;
      }
    </style>

<?php

//https://www.geeksforgeeks.org/how-to-insert-json-data-into-mysql-database-using-php/

	$json = file_get_contents('data.json'); 
  
	// Decode the JSON file 
	$json_data = json_decode($json,true); 
  
  
	echo "Nb de colonnes " .count($json_data);
  
  
	// Display data 
	echo "<pre>";
	print_r($json_data); 
	echo "</pre>";
	
	echo " ---> " .$json_data[0][0] ." -- " .$json_data[1][0] ." -- " .$json_data[2][0];
	echo "</br>";
	
	echo " ---> " .$json_data[0][1] ." -- " .$json_data[1][1] ." -- " .$json_data[2][1];
	echo "</br>";
	
	echo " ---> " .$json_data[0][2] ." -- " .$json_data[1][2] ." -- " .$json_data[2][2];
	echo "</br>";
	
	echo " ---> " .$json_data[0][3] ." -- " .$json_data[1][3] ." -- " .$json_data[2][3];
	echo "</br>";
	
	echo " ---> " .$json_data[0][4] ." -- " .$json_data[1][4] ." -- " .$json_data[2][4];
	echo "</br>";
	
	echo " ---> " .$json_data[0][5] ." -- " .$json_data[1][5] ." -- " .$json_data[2][5];
	echo "</br>";
	
	echo " ---> " .$json_data[0][6] ." -- " .$json_data[1][6] ." -- " .$json_data[2][6];
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
?>	
	<table>
	
	 <tr>
        <th>UN</th>
        <th>DEUX</th>
		<th>TROIS</th>
      </tr>
	
	
	
	
<?php	


	for ($i = 0; $i < count($json_data[0]); $i++)
	{
		$table_data = "";
?>	
		<tr>
<?php	
		for ($j = 0; $j < count($json_data); $j++)
		{
			//$table_data .= $j ." " .$i . " - " ;
			
			//"<th>" .$json_data[$j][$i] ."</th>"
			
			//$table_data .= $json_data[$j][$i];
			$table_data .= "<th>" .$json_data[$j][$i] ."</th>";
		}
		
		echo $table_data;
		
?>
		</tr>
<?php			
		
	}
?>	
	</table>

<?php	
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
	echo "</br>";
	
	for ($i = 0; $i < count($json_data); $i++)
	{
	
		//foreach($json_data as $row)
	 
  
				//print_r($json_data[$i]);  
				//echo "</br>";
				
				for ($j = 0; $j < 3; $j++)
				{
					$table_data .= $json_data[$i][$j];
				
					
					
				}
				
				echo $table_data;   
				echo "</br>";
				
				/*
					 $table_data .= ' 
                <tr> 
                    <td>'.$json_data[$i][$j].'</td> 
                    <td>'.$json_data[$i][$j].'</td> 
                    <td>'.$json_data[$i][$j].'</td> 
                </tr> ';
				
				}*/
				
               
               
                
     } 
	
	/*
	 echo ' 
                <table class="table table-bordered"> 
                <tr> 
                    <th width="45%">Name</th> 
                    <th width="10%">Gender</th> 
                    <th width="45%">Subject</th> 
                </tr> 
                '; 
                echo $table_data;   
                echo '</table>'; 
            
*/

?>