Hi All,
Come a little stuck with an issue and hoping someone can shed some light on it.
Basically, I have a form that pulls down the list of users and then pulls down a list of jobs that can be assigned to them. I can get the form to pull all this down, but when I post the data, I am unsure of how to process this for each user and insert into the database.
I have tried adding the [] onto the field name, but this doesn't work as one of the dropdowns that you choose the position for, populates another dropdown of site addresses you are allocating too.
I have attached the Script to see if anyone is able to assist with any guidance.
$userClient = "VARIABLE OF WHO IS LOGGED IN";
<form action="actions/assign.php" method="post">
<?php
$sql = "SELECT * FROM Engineers where Engineer_Company = '".addslashes($userClient)."' and userType = '5'";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_assoc($result)) {
$userSID = $row["userID"];
echo '<tr>
<td>'.$row["userName"].'
<input type="hidden" class="form-control" id="usersID[]" name="usersID'.$row["userID"].'" value="'.$row["userID"].'">
<input type="hidden" class="form-control" id="date" name="date" value="'.date('d-m-Y').'">
</td>
<td>';
$sql1 = "SELECT * FROM job_orders where companyID = '".addslashes($userClient)."'";
$result1 = mysqli_query($db, $sql1);
echo "<select style='width: 250px;' id='job$userSID' name='job$userSID'>";
echo '<option value="">-- Please Select --</option>';
while($row1 = mysqli_fetch_assoc($result1)) {
echo '<option value="'.$row1["jobID"].'">'.$row1["jobtitle"].'</option>';
}
echo "</select>";
echo '</td>
<td>';
$query = $db->query("SELECT * FROM Engineer_Company WHERE Company_ID = '".addslashes($userClient)."'");
$rowCount = $query->num_rows;
if($rowCount > 0){
echo ' <select name="company'.$userSID.'" id="company'.$userSID.'" style="width: 250px;">
<option value="">-- Select Company --</option>';
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['Engineer_Company_ID'].'" class="form-control form-control-sm">'.$row['Engineer_Company_Name'].'</option>';
}
echo '</select>';
}
echo'</td>
<td>
<div class="form-group">
<select id="site'.$userSID.'" name="site'.$userSID.'" style="width: 250px;">
<option value="">-- Select Site --</option>
</select>
</div>
';
echo'</td>
</tr>';
echo ' <script type="text/javascript">
$(document).ready(function(){
$("#company'.$userSID.'").on("change",function(){
var diag_id = $(this).val();
if(diag_id){
$.ajax({
type:"POST",
url:"ajax-client-side.php",
data:"diag_id="+diag_id,
success:function(html){
$("#site'.$userSID.'").html(html);
}
});
}
});
});
</script>';
}
?>
</tbody>
</table>
<input class="btn btn-dark float-right" type="submit" value="Allocate">
</form>
Cheers!