Solved

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

Posted on 2004-10-09
9
200 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
ID: 12268284
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
ID: 12268851
That would be assuming the student IDs and names are stored in a database at first.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 12269494
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:dougp23
ID: 12271250
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
 
LVL 1

Author Comment

by:dougp23
ID: 12271305
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
ID: 12271497
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
ID: 12272127
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
ID: 12274486
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
ID: 12277764
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 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