On Friday 07 March 2003 06:25, WebDev wrote: > How to grab the last -n lines from a data file and display the stored data > Only the the last 10 line numbers coming back when I echo $i > > How do I get the list($adnr, $user, $date, $listed .... to catch the > datafields > > datafile looks like > 23|Werner|LastN|Street|etc|etc.|etc|||||| > 24|Veronika|||| > > // code start > > > $file = file("data/ads.data"); > for ($i = count($file); $i > count($file) - 10; $i--) > foreach($i as $line) {
foreach() works on an array, $i is not an array. If you have error reporting on you would have caught this. In any case if you're using an outer for-loop as you're doing here then there is no need for a foreach(). OK, you can try this: $file = file("data/ads.data"); for ($i = 1; $i <= 10; $i++) { $line = array_pop($file); // the following have been copied verbatim from your post list($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei, $vier, $usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat, $ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3, $Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei, $dreidrei, $dreivier, $dreifunf, $dreisechs ) = split ("\|", $line); print " $i <a href=\"classifieds.cgi?session_key=&search_and_display_db_button=on&db_id=$adnr&query=retrieval\" target=\"_blanko\">$Endzwei $End3</a> <br>"; } ** Untested, use with caution ** -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* No wonder you're tired! You understood so much today. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php