Hello, how are you, I hope you have a good day. I am making a form where I add participants and events. Participants come out of a database in the users table. The events are added dynamically with text boxes and a select where the users who have been assigned as participants appear. Actually my challenge is when it comes to saving the participants in the events table. The events table has two participant fields and Event. It is assumed that in the participant column the id of the participants must be saved in the form of a string so that when consulting them an explode can be used and thus display the information. I just don't know how to pass the array that comes from the select to a string, the form fields are these:
<td class="col-md-2 td-a">
<input type="date" class="form-control evento" name="evento[]" autocomplete="off" />
</td>
<td class="col-md-4 td-a">
<select class="form-control participante" name="participante[]" autocomplete="off" />
</select>
</td>
<button class="btn btn-primary" type="submit"> Guardar</button>
I send the data by method $post
$evento = $_POST['evento'];
$participantes = $_POST['participante'];
After I iterate the array that interests me, which is the one of participants, I have done it in the following ways.
for($i=0; $i<sizeof($participantes; $i++){
echo $participantes[$i];
}
And I have also used a foreach
foreach($pasticipantes as $participante){
echo $participante;
}
My challenge is when using the variables of either participants[$i] or $participant outside the iterators, obviously it only prints the last value.
And when using array methods it does not allow me, my doubt is how I can use the values of the participants array to be able to save them in the database in a single record in the participants column. Or if I can create a new array with the format of $array = array(values) by iterating the array of $participants either with for, while or foreach. I thank you in advance for your time and I hope you can help me solve this in advance, thanks again.