Re: Writing to a text file

From: Date: Mon, 11 Sep 2000 02:11:07 +0000
Subject: Re: Writing to a text file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-16104@lists.php.net to get a copy of this message
On Sun, 10 Sep 2000 php@hotchilli.com wrote: <snip> > while ( $row = mysql_fetch_row($result )) > { > $site_id = $row[0]; > $host_name = $row[1]; > $domain_name = $row[2]; > $ip_address = $row[3]; > > > $filename = "httpd.conf"; > $fp = fopen( "httpd.conf", 'w' ); > print "Writing to $filename $row[1].$row[2]<br>"; > $fp = fopen( $filename, "w" ) or die("Couldn't write to $filename"); First, why do you have two fopen() calls for the same file?? Also, the fopen() call should be done before the while loop, not inside the loop. You don't change $filename within the loop, so you're not outputting to different file. Each time through the loop, when you do the fopen(), you get a new handle to the output file. So what appears, to me, to be happening is that each output in the loop overwrites the previous output. That's why you end up with only the last output in the actual file. John

« previous php.general (#16104) next »