Hi, I am a newbie to php and am trying to copy mysql data to a text file. The format I need to create is
{
"data": [
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
My code generates the file but does not enter the mysql data. Below is an excerpt from the code relating to the fwrite function.
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "{\n\"data\": [\n";
fwrite($fh, $stringData);
$dbstringData[] = implode(",",$row);
fwrite($fh, implode("\r\n", $dbstringData));
$stringData = "{\nTracy ,\n},\n";
fwrite($fh, $stringData);
$stringData = "]\n}\n";
fwrite($fh, $stringData);
fclose($fh);
?>
Thanks.