Hi
I have a HTML datatables that I load using inline PHP. One of the table fields is a dropdown, and is the only field that is changable.
The code I use is:
SELECTS:
$groupqry = $conn->query("SELECT group_id, groupname FROM classgroup WHERE class_id= " . $class) or die("groups query : " . mysqli_error($conn));
$g_query1 = $conn->query(“SELECT m.mem_id, AES_DECRYPT( m.firstname, '” . $token . “’) AS firstname, AES_DECRYPT(m.lastname, '” . $token . "’) AS lastname, m.gender, m.dob, c.group_id FROM classmember c INNER JOIN memberdetails m ON c.mem_id = m.mem_id WHERE c.class_id= " . $class) or die("Gymnast query: " . mysqli_error($conn));
The classgroup table consists of:
class_id
group_id
groupname
and each class can have between 1 and 6 groups
The classmember table consists of:
class_id
mem_id
group_id
The Table code:
<table id = "table" class="table table-striped table-bordered dt-responsive nowrap table-sm" width="100%"> <thead class="bg-secondary text-white"> <tr> <th>Name</th> <th>Gender</th> <th>Age</th> <th>Group</th> </tr> </thead> <tbody class="bg-light text-dark"> <?php while ($f_query = $g_query1->fetch_array()) { echo '<tr>'; echo '<td>' . $f_query['firstname'] . ' ' . $f_query['lastname'] . '</td>'; echo '<td>' . $f_query['gender'] . '</td>'; echo '<td>' . getAge($f_query['dob']) . '</td>'; $grpid = $f_query['group_id']; echo '<td><select name = "group">'; $optid = "0"; selectdCheck($optid,$grpid,"-----"); while ($grp = $groupqry->fetch_array()) { $optid = $grp['group_id']; selectdCheck($optid,$grpid,$grp['groupname']); } $groupqry->data_seek(0); echo '</select></td>'; echo '</tr>'; } ?> </tbody> </table>
The selectdCheck function code:
function selectdCheck($value1,$value2, $display)
{
if ($value1 == $value2)
{
$select = ‘selected=“selected”’;
} else
{
$select = ‘’;
}
echo ‘<option value ="’.$value1.’" '.$select. ‘">’ .$display. ‘’;> $grp[‘groupname’] . ‘’;
return;
}
Basically this all works - the correct data is selected and displayed, and I can change the group using the dropdown on each table row.
I was quite pleased how this worked. Then I realised I hadn’t worked out how to save back to the classmember table any changes made to members groups.
There will be no changes to the number of records, it is just that some records will have the group_id changed to match the option id.
I assume I will need to put the datatable into a form to allow a SUBMIT, but other than that I am lost.
Can anyone let me know how to do the update based on the above code?
Thanks