Question

In WordPress, I have a FusionCharts div in a page called "JSON" that points to a file called jsontest.php. jsontest.php contains the following code that generates a JSON file.

<?php

$result=mysql_query ("SELECT date, last_close_eur FROM pricing limit 10");

$i=0;
while($row=mysql_fetch_array($result)) { 
    $response[$i]['DATE']  = $row['DATE']; 
    $response[$i]['LAST_CLOSE_EUR']= $row['LAST_CLOSE_EUR'];
    $data['posts'][$i] = $response[$i];
   $i=$i+1;
} 

$json_string = json_encode($data);

$file = 'file.json';
file_put_contents($file, $json_string); 
?>

Output file does not contain any data. Any idea?

Was it helpful?

Solution

Try this:

...
$file = dirname(__FILE__). '/file.json';
file_put_contents($file, $json_string); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top