Zixtyy Posted November 29, 2012 Share Posted November 29, 2012 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2012 Share Posted November 29, 2012 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. Quote Link to comment Share on other sites More sharing options...
Zixtyy Posted November 29, 2012 Author Share Posted November 29, 2012 I..I'm still not sure. Can you clarify what you mean by form field name and array key? (Or spoonfeed me, lol, I'm desperate) Quote Link to comment Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 Don't store separate day/month/year - use a TIMESTAMP then it will update automatically. It may also be an idea to hold whether they were present/absent/late in the table Quote Link to comment Share on other sites More sharing options...
Zixtyy Posted November 29, 2012 Author Share Posted November 29, 2012 I chose the separate column part so I could easily sort the data for analytics etc (month-by-month attendance rates etc). + I just realised I'd forgotten to type that on the post - it's there really! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 29, 2012 Share Posted November 29, 2012 Using one of the inbuilt date types does not stop you doing monthly analyses and does give you far greater functionality. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2012 Share Posted November 29, 2012 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. } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.