Jump to content

Processing Pupil School Register


Zixtyy

Recommended Posts

Hi,

 

I'm working on my Computing project for A2, and I'm a little stuck on working out how to process a bunch of data for a pupil register.

 

At the moment, the process works by the script pulling the classes which a teacher is assigned to, and then the pupils assigned to the class, and displaying them in a table, along with a dropdown box for a mark for the teacher to select, Present, Absent or Late.

 

However, i'm not sure how I can process each line, match it with a specific pupil ID, attach a timestamp and send it off to the database. (As in taking POST data and parsing it into queries.)

 

The code which presents the options is currently:

 

echo "<td><select name='mark-" . $row2['id'] . "'><option value='Present'>Present</option> <option value='Absent'>Absent</option><option value='Late'>Late</option></td>";

 

(Assigns the pupils ID to the select box name)

 

Fields in the attendance table are:

RecordID, PupilID, Day, Month, Year

 

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

You should use an array for the form field name, with the id as the array's key so that when the $_POST data is submitted you can use php's array function(s) to iterate over the data -

 

name='mark[{$row2['id']}]'

 

This will result in $_POST['mark'] being an array with the key being the id and the value being the option value that was selected.

Link to comment
Share on other sites

Can you clarify what you mean by form field name and array key?

 

The post I made above that shows the change for the form field name. To iterate over the submitted data -

 

foreach($_POST['mark'] as $id=>$value){

   // $id will be the original $row2['id'] value and $value will be the selected option's value.

}

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.