I am trying to output the results from a MySQL query to both the screen and a text file. I am able to get the screen output correct, but when I save it to a file only the last result is saved. Here is my code:
$total_rows = mysql_num_rows($filter_result);
for ($i=0; $i < $total_rows; $i++) {
$filter_row = mysql_fetch_array($filter_result);
$outputstring = $filter_row['MailingAdd'].'<br><br>';
echo $outputstring;
}
// write results to text file
$file = "mail_list/mailing_list.txt";
$fp = fopen($file, 'w');
flock($fp, LOCK_EX);
fwrite($fp, $outputstring);
flock($fp, LOCK_UN);
fclose($fp);
Thank you for your help in advance.
Cassandra