Jump to content

fwrite() question..


gaza165

Recommended Posts

i am pulling back a record from the database on every click of the submit button...

 

what i want to do is write the data im pulling from the database into a text file.

 

the code i have just overwrites the previous data. i want it to keep adding on to it like below.

 

{ "id": "10","nick":"Garry","message":"yeah good mate you?","time":"0.00104808807373"}

{ "id": "11","nick":"Dan","message":"yo!","time":"0.00115013122559"}

 

 

this is the code i am using.

 

<?php
$data = array();
while ($row = mysql_fetch_array($result))
{
	$data[] ='{ "id": "'.htmlentities($row['chat_id']).'","nick":"'.htmlentities($row['nick']).'","message":"'.htmlentities($row['message']).'","time":"'.$time.'"}';

	$fp = fopen('chat.txt', 'w');
	fwrite($fp, $data[0]);

} 

$json = '{"latest":"'.$lastid.'","response":[';
$json .= implode(',',$data);
$json .= ']}';

echo $json;
?>

Link to comment
https://forums.phpfreaks.com/topic/137540-fwrite-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.