Need some PHP Code, Trying to do much on one page?


I am developing a web based "progress report" system for a school.  So on one page, I say "enter Grade, teacher name, subject, and Term".  once the teacher enters that (and presses submit), I query the DB (MySqL) for the # of kids, and then we move to the next page.

On the next page, I create the array of student IDs and names.  I am able to say "Enter progerss report for " and I get the first students name (using current function in PHP).  Under this, there are numerous radio buttons for the teachers (Conduct - Good, bad, ugly, Effort - Good Bad Ugly, Homework -Same, etc.) and then a comment box.  

I want two hyperlinks at the bottom (submit, which would write all the choices to the DB), and Next, which would skip this student (since not all teachers have all the kids).  of course, once eitehr hyperlink is chosen, we need to refresh the page, show the next kids name, etc.

How do I do that part?  Since I create the array on this page, if I just reload thepage, wouldn't I be recreating the array? How do I move to the next student?

Sorry if this is lengthy, I am trying to be explicit!
Any help would be great!
Who is Participating?
cachedVBConnect With a Mentor Commented:
right after session_start();
add the line $_SESSION[studentid]++;
and only use row ($_SESSION[studentid] - 1) from the database each time
you can have a session variable which is an integer and increase it by 1 everytime a page is loaded, and select that row from the database.
That would be assuming the student IDs and names are stored in a database at first.
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Why wouldn't you use a kind off big table with a row for each user and first col name, other colls radio buttons, like they use in online questionaires?

But as to your question about passing students array. You could use a session. You could also output something like:
<input type="hidden" name="nextstudents[]" value="s0002" />
<input type="hidden" name="nextstudents[]" value="s0003" />
<input type="hidden" name="nextstudents[]" value="s0004" />
<input type="hidden" name="nextstudents[]" value="s0005" />

And when clicked next, the first one would be popped off offcourse and things would look like
<input type="hidden" name="nextstudents[]" value="s0003" />
<input type="hidden" name="nextstudents[]" value="s0004" />
<input type="hidden" name="nextstudents[]" value="s0005" />

Quite obviously you could use
<input type="submit" name="submit_skip" value="Next/">
<input type="submit" name="submit_save" value="Save/">

And check with if(isset($_POST['submit_skip'])) in php.



dougp23Author Commented:
Wow, thanks all.

But, here's my problem ( I think).  The script to load the page goes like this (It's on my other system, so I'm gonna do it from memory!)

1.  session_Start()   (to preserve and get anything from last script, i.e. teacher name, grade, etc.)
2.  connect to DB, create the array.
3.  create the html with radio buttons and comment box.
4.  Display the first kids name.
5.  have user enter data, then click appropriate button/hyperlink.

So, my feeling is, If I write to the db, and reload this script, don't I recreate the array all over again?  I want to make sure I don't recreate the array (I'm new top PHP, so this may not even be an issue!)  Should I offload the creation of the array to another script and use sessions to read what's next in the array?  Could I do a While -> For loop in this script on the array, and after the user chooses a button, get the next record in the array and just stay in the same script?

dougp23Author Commented:
Let me clarify, there are 2 tables here!
Teh first one (the one I create the array with) will be static, I am just pulling info from it (student ID, which may NOT be sequential,) and then the second table will store what the user inputs.

I hope that helps!
dougp23Author Commented:
It doesn't matter that studentid's may NOT be sequential?? (in most cases, they are, but if a student moves or drops out, we do not reassign the id, the next student gets an all new id.  So we could have 400111, 400112, 400113, then 400116 because 2 kids have moved).

Does it matter that I build the array in this script?

You can use the LIMIT keyword in your SQL and increment that every time the page is loaded  (That's assuming the contents of the table are not changed.

I (think I) don't see the problem...

Since you're already using sessions, why not just test for the array's existence and if it doesn't yet exist (1st execution of script) then create it and add it to the 'storage' (with other session vars). If it does exists, then just use it with whatever you fancy as an increment counter... (?)

(well, that only take care of the 'not recreating array'..  Which actually wouldn't be that important : unless you have thousands of teachers, the overhead wouldn't exactly be 'that bad'. -- Maybe I missed some more important issue?)
All Courses

From novice to tech pro — start learning today.