I have a bunch of files with data formated as follows: int|int|string|string
I have some functions to get all files in a directory, format their names and make a select drop-down menu from that.
From that, the user selects the file he wants to open.
The choosen file (its filename) gets send via POST to a second php file that opens in an iframe right below the drop-down form.
These are the relevant contents of said file:
<table>
<thead>
<tr>
<th>A:</th>
<th>B:</th>
<th>C:</th>
</tr>
</thead>
<tbody>
<?php
$fl = $_POST["file"];
$currentfile = fopen("./dir/$fl","r");
if ($currentfile) {
while (($line = fgets($currentfile)) !== false) {
$n = sscanf($line, "%d|%d|%[^|]|%[^\n]", $a,$b,$c,$d);
print "<tr><td>$a</td><td>$b</td><td>$d</td></tr>";
}
fclose($currentfile);
} else {
print "Error: Couldn't open file.<br>";
}
?>
</tbody>
</table>
Now somehow, the first line in each file isn't shown in the table generated by this, everything else is fine.
As an example, here's one file.
1|334|Item 1
2|837|Item 2
3|321|Item 3
4|124|Item 4
5|331|Item 5
etc...
And this is the output I get.
A: B: C:
2 837 Item 2
3 321 Item 3
4 124 Item 4
5 331 Item 5
etc...
Or in code:
<table>
<thead>
<tr>
<th>A:</th>
<th>B:</th>
<th>C:</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>837</td>
<td>Item 2</td>
</tr>
<tr>
<td>3</td>
<td>321</td>
<td>Item 3</td>
</tr>
<tr>
<td>4</td>
<td>124</td>
<td>Item 4</td>
</tr>
<tr>
<td>5</td>
<td>331</td>
<td>Item 5</td>
</tr>
etc...
</tbody>
</table>
So as you can see by above code, the td tags get printed, but there's no data in them, whereas the second set of td tags have the second line of data in them, as it should be, so why doesn't it read, scan and print the first line of the file?