Help finding an error in this code please

S

ShockingAlberto

Guest
ok, for a site i'm amking a nice news script.
i'm fairly new to php, but from a book i've been learning it well, the only thinbg i have problems with are the loops which allways confuse me.

the display part of my news script isn't working, due to those horrid parse errors. but i cant find anything to cause a parse error...

i'm getting errors on line 9, and if i remove that line i get them it on line10(basically the same thing).

Code:
<?php
function readnews(){
$newsfile="news.txt";
$open=fopen($newsfile, "r");
if($open){
$data = file($newsfile);
for ($n=count($data); $n>0;$n-2){
$m = $n-1
$getheader=$data[$m]; //this is line 9 fyi
$getnews=$data[$n]; //and this is line 10, basically the same ting
print("
<tr><td width=\"580\" height=\"15\" bgcolor=\"#CE5A1D\">$getheader</td></tr><tr><td width=\"580\">$getnews</td></tr>
");
}
fclose($open)
print("<hr>

/n");
}else{
print("Error reading from news file!");
}
} 
?>
if you notice the script itself is wrong, dont tell me, i need to learn myself, it's just that i cant see why i'm getting parse errors on these 2 lines.

the function is designed to go in a table, so ignore the html parts, cus it makes sense.

here's what the script does:
it reads from a opens the file, and should get the contents, and put them into an array. since the newst news is added at the end of the file, it will print the 2 parts of the array(and thus 2 lines from the file)first, and hopefully the loop will make it go down the file printing each news header and then the actual news.
i have a feeling i've messed up for for loop, but i dont mind, i just wanna know what's wrong on lines 9 and 10, where it should take right pparts from the array, into the string.
since there's no basic mistakes there, i guessi need to re-read about arrays or soemthing, but if someone could [point out what's wrong with those lines it would really help :)
 
T

Teaser

Guest
I've not played with file opening so I can't look at that with any confidence, but you don't have a semi-colon after: $m = $n-1 but that may be a typo when posting.
 
W

whipped

Guest
Just a thought. The parse error could be anywhere above line 9.

Try changing your file($newsfile) to file($open) . The fopen command returns a file handle that is used in all I/O. The $newsfile is specified in the fopen function and assigned to the file handle $open.

You say you have a book. If you haven't already, I would visit www.php.net and download the php manual. There are some great titbits in there.

Oh and check that semi-colon after $m = $n -1 cause it probably is that
 
S

ShockingAlberto

Guest
gah, sorry, i asked on the TPF forum at the same time, and one of the guys there is a web programmer, so he pointed out the lack of a semi-colon on the line before as u say, the rest of it works fine though so no problems :)
 

Users who are viewing this thread

Similar threads

S
Replies
2
Views
541
wyrd_fish
W
M
Replies
2
Views
565
Maljonic
M
W
Replies
0
Views
540
wyrd_fish
W
R
Replies
8
Views
782
wyrd_fish
W
P
Replies
3
Views
729
wyrd_fish
W
Top Bottom