I'm trying to generate a json file with PHP with the code below and I'm getting an empty array -> {"posts":[]}. I'm using Wordpress. Can someone assist me. Thanks
$sql=mysql_query("SELECT * FROM wp_posts");
$response = array();
$posts = array();
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$url['url']=$row;
$title['title']=$row;
$posts[] = array('url'=> $url, 'title'=> $title);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
mysql_query()twice. And the second time, when you try to get the result set, you are calling it on the result from the first$sql. Turn on error reporting and display_errors, and you'll see PHP complain about that.