Jump to content

vegac

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by vegac

  1. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.