Puoi usare la funzione json_encode.
- Recupera i dati dal db e assegnali a un array
- Poi usa
json_encode($result_array). Questo produrrà il risultato JSON. Clicca qui - Usa la funzione
file_put_contentsper salvare il risultato JSON nel tuo file .json
Di seguito un esempio di codice:
$result = mysql_query(your sql here); $data = array(); while ($row = mysql_fetch_assoc($result)) { // Generate the output in desired format $data = array( 'cols' => .... 'rows' => .... 'p' => ... ); } $json_data = json_encode($data); file_put_contents('your_json_file.json', $json_data);