Jump to content

Archived

This topic is now archived and is closed to further replies.

jeaker

Trouble with file editing???

Recommended Posts

I want to be able to allow the user to pull in the file grades.txt for editing. The user should be allowed to add a name a series of grades, change grades on existing data, or add grades to an existing student. I want to use -2 as the end of file indicater and -1 as the end of line mark.
(ex. john
doe
23
34
98
-1
jane
doe
21
32
-2)
If anyone can help me with this it will be greatly appreciated and thanks sooo much in advance.
Here is some code that i have gotten together so far.
[code]<html>
<head>
<title>Edit Student Data</title>
</head>
<body>
<?php
$line = file("Grades.txt");
$i = 0;
$num = 0;
$cnt = 0;
while ($line[$i] != -2) {
      $first = $line[$i];
      $i++;
      $last = $line[$i];
      $i++;
  while ($line[$i] != -1) {
        $num = $num + $line[$i];
        $cnt++;
        $i++;
        }
$num = $cnt > 0 ? $num / $cnt : 0;
echo "$last, $first, $num<br />";
$i++;
$cnt = 0;
$num = 0;
}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.