[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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

Hi.

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!
0
dougp23
Asked:
dougp23
  • 3
  • 2
  • 2
  • +2
1 Solution
 
cachedVBCommented:
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.
0
 
dennisttCommented:
That would be assuming the student IDs and names are stored in a database at first.
0
 
RoonaanCommented:
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.

Regards

-r-

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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?

Thanks!
0
 
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!
0
 
cachedVBCommented:
right after session_start();
add the line $_SESSION[studentid]++;
and only use row ($_SESSION[studentid] - 1) from the database each time
0
 
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?

0
 
dennisttCommented:
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.

0
 
PaulPositionCommented:
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?)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now