doucuo9126 2014-01-26 15:08
浏览 58
已采纳

wordpress中的PHP文件生成融合图的json文件

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?

  • 写回答

1条回答 默认 最新

  • douzhuican0041 2014-01-26 15:22
    关注

    Try this:

    ...
    $file = dirname(__FILE__). '/file.json';
    file_put_contents($file, $json_string); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?