[thelist] PHP & Last Entry in Flat File DB was: (no subject)

John Corry webshot at members.evolt.org
Tue May 7 17:48:01 CDT 2002

> >database - that is out of my hands. Can anyone give me a
> clue as to how
> >to find the first field of the last record in a text file?

I'm kind of a newbie at this stuff...but this looks like a fun problem
to try to solve:

$last_entry_id = '';
$file = 'your_file.txt';

// open the file for reading
$fp = fopen($file, "r");

// file() returns array of file's lines, we're counting lines here
$last_line = count(file($file));

// read last line
While ($data = fgetcsv($fp, $last_line, ',')
		if ($data[0] == $last_line)
				$the_last_entry = $data[0];


Cool, that's totally untested...I wrote it in my mail client :)

Maybe it will send you in the right direction...


More information about the thelist mailing list