if and while writing to a txt file!

From: Date: Fri, 14 Jul 2000 07:30:37 +0000
Subject: if and while writing to a txt file!
Groups: php.db php.general 
Request: Send a blank email to php-db+get-1140@lists.php.net to get a copy of this message
Hi there! I'm currently making a phtml page that writes to a .txt file Registering books and empl_no, like this: bookno empl_no empl_no .... 1 55555 22222 2 55555 44444 78965 I want: 1. If the book exist in the txt file I want the empl_no added at the end. 2. If the book don't exist in the txt file I want the bookno and empl_no added on a new line. This is my source: <? $filnavn = "liste.txt"; $fpr = fopen($filnavn, "r"); $funnet = false; $nyfilnavn = "nyliste.txt"; $nyfpr = fopen($nyfilnavn, "w+"); while($innhold = fgets($fpr, 4096)) { $do_explode = explode(" ", $innhold); // Book exist add empl_no at end if ($do_explode[0] == $no) { $funnet = true; $count = count($do_explode) - 1; fwrite ($nyfpr, $innhold . " " . $empl_nr); } fwrite ($nyfpr, $innhold); echo "skriver gammelt"; } // Book don't exist add it! if ($funnet == false) { echo "Du er nå satt på ventelisten"; fwrite ($nyfpr, "\n$no $empl_nr"); } copy($nyfilnavn, $filnavn); chmod ($filnavn, 0755); fclose ($nyfpr); ?> Is it best to write the information to a temp file? I've done something wrong here because it don't seem to work! I also have a problem executing chmod 777, it says permission denied! Do I have to execute chmod when copying a file? ANY SUGGESTIONS IMPROVEMENTS?! Please write back! ------------------ Best Regards Fredrik Arild Takle ftakle@online.no

« previous php.db (#1140) next »