Forum Moderators: coopster

Message Too Old, No Replies

PHP Attendance System

Php Attendance System checkboxes

         

xa3021

4:02 am on Dec 20, 2007 (gmt 0)

10+ Year Member



Ok, first off this site is very helpful, although this is my first post I have gotten a lot of info from it. Heres what Im doing...I want to create a page where a person can take "attendance". It will get the list of names from the database and I want it to be able to enter a date and then to go down the list and select who is present by a check box (check if here and don't check if not) with the list of names sometimes growing and sometimes shrinking what would be the best way to send this data to a database? I also would like for them to view the data back on the page at a later time but I'm 99% sure if I can get help on sending the info to database I will be able to retrieve it the way I want. Please help ASAP and email me if you have more questions. Thanks in advance!

[edited by: coopster at 4:27 am (utc) on Dec. 20, 2007]
[edit reason] removed email per TOS [webmasterworld.com] [/edit]

cameraman

6:01 am on Dec 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, xa3021!

I see three basic approaches, and which way you do it depends on your overall motivation for taking the attendance. The first is 'student-centric', where your primary concern is that the student is attending classes. The second is 'teacher-centric' where you're concerned with how many people are attending the class, perhaps to determine payment. The third is a hybrid wherein you want to be able to easily retrieve the information from either perspective.

All three will require a students table with the student's name and hopefully a unique ID number.

A teacher-centric approach would require a table for the classes. Depending on how you prefer to retrieve the data, you could either have a field for the date and a text field to hold a comma (or other character, doesn't matter) delimited list of student IDs, or you could put each student id on a separate table row. If you have more than one class/teacher on any given day, you'd also want a field to denote the class/teacher and probably another table to hold a registry of teachers or classes. I'd use separate rows.

For a student-centric implementation you could either set up a text field in the student table for a comma-delimited list of attendance dates or you could set up a separate table with fields for student id and date. I recommend the latter.

The hybrid approach would use a student table, a teacher/class table, and attendance table. The attendance table would have fields for student id, teacher/class id, and attendance date.

Personally I'd do the hybrid method since you never know what sort of report someone will want you to produce next week. You wind up with table data comprised of lots of couples or triplets of numbers, but computers get to sort it out and they love numbers so who cares.

I would lay out the form so that all of the checkboxes had the same name as an array, e.g. <input name="attendee[]" and the student's id as the value. I would store the dates as unix timestamps.

xa3021

12:40 am on Dec 21, 2007 (gmt 0)

10+ Year Member



Hey thanks for your advice. I have it the students set-up in a table with a id, firstname, lastname, and more info. So should I make a separate table with an id, date, and students? or what? Also what would the code look like to submit this information to the database? Please let me know if you have an IM service or something so I can get out of hair faster. Thanks!

cameraman

7:09 am on Dec 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I used to have aim but the last time I upgraded it, it messed a bunch of stuff up so I got disgusted and uninstalled it.

Your existing students table is fine, unchanged.

Make a new table (we'll call it ledger) with columns for classdate (big int) and student id. If you're dealing with more than one teacher/class, add a third column for class id. The primary key for the table is all of the columns.

You'll build the form by doing a SELECT query on your students table, like with
$qry = mysql_query("SELECT recID,lastname,firstname FROM students ORDER BY lastname, firstname");
while($dat = mysql_fetch_assoc($qry))
echo '<input type="checkbox" name="students[]" value="' . $dat['recID'] . '">' . $dat['lastname'] . ', ' . $dat['firstname'];

When the form is POSTed, do:
$tm = strtotime($_POST['date']);
foreach($_POST['students'] as $id)
mysql_query("INSERT INTO ledger (classdate,id) VALUES ($tm,$id)");

Doing it this way allows you to retrieve all records matching a particular student id, attendance date or particular teacher/class.

You can learn more about using php to store and retrieve data from mysql by looking in this forum's library. A good thread to look at is:
Basics of extracting data from MySQL using PHP [webmasterworld.com]