Re: Writing & Displaying Records

From: Date: Thu, 05 Oct 2000 21:22:55 +0000
Subject: Re: Writing & Displaying Records
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-18772@lists.php.net to get a copy of this message
Hi Andrew: > On Thu, 05 Oct 2000, Andrew V. Romero wrote: > > > $wd=fopen("writedata.txt","a"); > > > $wdata=fwrite($wd,$data); > > > fclose($wd); > > > $wd=fopen("writedata.txt","r"); > > > $currentdata=fgets($wd,50); > > > echo "<br>Data Currently in File: $currentdata"; > > > but that jams all the data entered by the various users together and I > > > can't figure out how to seperate it out when I am trying to display it. Then, David Robley said: > > Presumably the records in your text file are separated by carriage returns? What he means is to add carriage returns/line breaks at the end of each line you save by doing this instead of the step you had. $wdata=fwrite($wd,"$data\r\n"); Then, on output you can either echo "<pre>"; before your output and then a echo "</pre>"; after your output. OR do $currentdata = nl2br( fgets($wd,50) ); But, how are you going to see all your records? You've only set up your script to get the first line of the file. You'll either need to do a while loop with the fgets() or do an fread(). I'd do the latter. So, substitute this line $currentdata=fgets($wd,50); with this: $currentdata = nl2br( fread( $wd, filesize("writedata.txt") ) ); By the way, you safe some time by having the initial file open set up for append AND read by doing $wd=fopen("writedata.txt","a+"); Then, after you've done the write, you can put the file pointer at the beginning by doing rewind($wd); and continue with your fgets(); Enjoy, --Dan -- T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y More than just answers. Solutions. (SM) http://www.analysisandsolutions.com/ 4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#18772) next »