Jump to content

Trouble with file editing???


jeaker

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.