Working on an attendance database where you can assign people to classes held in an event.
It's also possible for a member to attend multiple classes in a single day for my purposes.
When a user creates an event, he/she will then have to assign members to said event. I've created a form that populates a checkbox in the first column the member's name in the second column, then a drop-down list of available classes in a third column.
| Checkbox | Member Name | Class dropdown list |
--------------------------
----------
----------
----------
-
[X] | Bob | Class C
[ ] | Joe |
[ ] | Betty |
[X] | Mike | Class A
*checkbox NAME=mem[] VALUE=$row[mem_id]
*dropdown NAME=credit$row_count VALUES=Class A, Class B, Class C, etc
In need a mySQL query that will only 'INSERT' the pertaining dropdown info, along with mem_id that have the checkboxes checked.
(Or, only Bob [Class C] and Mike [Class A] in the above example)
==========================
=====
Here's some extra info
==========================
=====
Here's the Credits table structure:
+-------------------------
----------
----------
----------
-------+
| Table 'Credits' |
+-------------------------
----------
----------
----------
-------+
| evt_id | mem_id | Class A | Class B | Class C | etc.... |
+-------------------------
----------
----------
----------
-------+
Here's the code I've been trying (it's wrong). Getting the mem_id has always been correct, but the dropdown data always gets mismatched.
$evt_id = $_GET['evt_id'];
for($i=0;$i<sizeof($_POST[
mem_id]);$
i++)
{
$class = $_POST['credit'.$i];
$mem_id = $_POST[mem_id][$i];
$query="INSERT INTO credits (evt_id, mem_id, $class) VALUES ('$evt_id', '$mem_id', '1')";
$result=mysql_query($query
);
}
*I've also tried naming the dropdowns as credit[] to create an array, along with '$class = $_POST['credit'][$i];' in the query. But that doesn't work either.
(could it be that mem_id is relative to the number of checked boxes, while dropdown are 'static')
Start Free Trial