I use some code here, transfer mysql query data into json data and write into a file. where is the problem? why the file is zero kb?
while($row = mysql_fetch_array($Query)){
$arr = array ('name'=>$row['name']);
$jsondata = json_encode($arr);
$countfile="data.txt";
if(!file_exists($countfile))
{
fopen($countfile,"w");
}
$fp = fopen($countfile, 'r');
fwrite($fp, $jsondata);
fclose($fp);
}
Because you’re reopening the file as read only
$fp = fopen($countfile, 'r');try
$fp = fopen($countfile, 'w'); // to writeor
$fp = fopen($countfile, 'a'); // to appendyou could also open the file for writing at the start, append your rows in a variable and then write it all together to the file.