How to implement write to PHP after the execution of multiple records to TXT file, every time the PHP page is overwritten to write new records to the TXT file, thank you!
I generated multiple records in PHP with a switch case, but only the last record was written to TXT, and the previous record was overwritten.
If the fopen () function uses "a", it can write multiple records, but each time the PHP page refresh will be in the TXT file after the original content to write, not up to the time I want to refresh PHP, the effect of re-write txt. May I ask what method can be realized, thank you!
PHP Files:
$sql = "SELECT * from Log";
$query =mysql_query ($sql);
while ($rs =mysql_fetch_array ($query))
Switch ($rs [' status '])
{
Case 1:
$STR = $rs [' id '];
$fp = fopen ("Test.txt", "w");
Fwrite ($fp, $STR);
Fclose ($FP);
Break
}
?>
Reply to discussion (solution)
Put
$fp = fopen ("Test.txt", "w");
Fclose ($FP);
Move outside the while loop
$sql = "SELECT * from Log"; $query =mysql_query ($sql), $fp = fopen ("Test.txt", "w"), while ($rs =mysql_fetch_array ($query)) { switch ($rs [' Status ']) {case 1: $str = $rs [' id ']; Fwrite ($fp, $str); Break
Reference
$fp = fopen ("T.txt", "w"), for ($i = 0; $i < 4; $i + +) {fwrite ($fp, $i);} Fclose ($FP);
Thanks for the help!!