Solved

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

Posted on 2004-10-09
9
198 Views
Last Modified: 2008-03-06
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
Comment
Question by:dougp23
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 4

Expert Comment

by:cachedVB
Comment Utility
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
 
LVL 1

Expert Comment

by:dennistt
Comment Utility
That would be assuming the student IDs and names are stored in a database at first.
0
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
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
 
LVL 1

Author Comment

by:dougp23
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:dougp23
Comment Utility
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
 
LVL 4

Accepted Solution

by:
cachedVB earned 125 total points
Comment Utility
right after session_start();
add the line $_SESSION[studentid]++;
and only use row ($_SESSION[studentid] - 1) from the database each time
0
 
LVL 1

Author Comment

by:dougp23
Comment Utility
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
 
LVL 1

Expert Comment

by:dennistt
Comment Utility
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
 
LVL 3

Expert Comment

by:PaulPosition
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now