Re: writing to txt-file! if and else!
| From: | Jerry | Date: | Wed, 12 Jul 2000 15:14:17 +0000 |
| Subject: | Re: writing to txt-file! if and else! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-6153@lists.php.net to get a copy of this message | ||
In article
<4263970.963397964027.JavaMail.webmail2@wm-java2.fg.online.no>,
ftakle@online.no (Fredrik Arild Takle) wrote:
> <?
> $filnavn = "liste.txt";
> $fpr = fopen($filnavn, "r");
>
> while($innhold = fgets($fpr, 4096)) {
> $do_explode = explode(" ", $innhold);
> if ($do_explode[0] <> $no) {
> $count = count($do_explode) - 1;
> for ($i = 1; $i <= $count; $i++)
> echo "Book already exists ($count in que!)";
> \\add to end of line here
>
> }
> if ($do_explode[0] == $no) {
> $filnavn = "liste.txt";
> $fpr = fopen($filnavn, "a+");
> \\new entry here
> // fclose($fpr);
> fwrite ($fpr, "\n$no $empl_nr");
> // fclose($fpr)
> } }
> ?>
One thing that can help, I think, is to use indentation to show where
you are in the various loops and conditionals:
<?
$filnavn = "liste.txt";
$fpr = fopen($filnavn, "r");
while($innhold = fgets($fpr, 4096)) {
$do_explode = explode(" ", $innhold);
if ($do_explode[0] <> $no) {
$count = count($do_explode) - 1;
for ($i = 1; $i <= $count; $i++) {
echo "Book already exists ($count in que!)";
}
\\add to end of line here
}
if ($do_explode[0] == $no) {
$filnavn = "liste.txt";
$fpr = fopen($filnavn, "a+");
\\new entry here
// fclose($fpr);
fwrite ($fpr, "\n$no $empl_nr");
// fclose($fpr)
}
}
?>
I don't quite understand what you're trying to do, but this might give
you a better understanding of what's wrong.
Jerry