I have two arrays that come out of two select multiple that I want to combine to store them in mysql
I am using a foreach to go through one of them but I would like to know if there is the option to go through both and store them, so far this is the code I use.
foreach($_POST["dato"] as $Dato) {
foreach($_POST["dato2"] as $Dato2) {
$INuevo = Insertar_Datos("Codigos" ,"'que','idcosa','1','2'" , "'test','$Id_Numero','".$Dato."','".$Dato2."' ");
}
}
The case is that I want to loop the first read a data of the first array and then run the second inserting data from the second with a value of the first (with this in principle I have no problem once you know what would be the variables that I have to pass to the query). For example, suppose the data is first and last:
name = 1
last name = 1 of name 1
last name = 2 of the name 1
surname = 3 of the name 1
name = 2
last name = 1 of the name 2
last name = 2 of the name 2
last name = 3 of the name 2
and thus until the end of the days being able to have only two surnames or one single.
Can I or do I have to do another foreach inside the foreach? Maybe a for inside the first foreach is better?
Inside the function Insert_Data I have this:
function Insertar_Datos() { global $Conectar;
$Parametros = func_get_args();
$InDatos = "INSERT INTO '".$Parametros[0]."' (".$Parametros[1].") VALUES (".$Parametros[2].");";
$RDatos = mysqli_query($Conectar, $InDatos);
if (!$RDatos) { http_response_code(500); print(mysqli_error($Conectar)); } else { http_response_code(200); echo "ok"; }
return $RDatos;
}
and the multiple selections are something like this:
<select name="dato[]" multiple="multiple">
<option value="1">Numero 1</option>
<option value="2">Numero 2</option>
<option value="3">Numero 3</option>
</select>
<select name="dato2[]" multiple="multiple">
<option value="1">Numero 1</option>
<option value="2">Numero 2</option>
<option value="3">Numero 3</option>
</select>
The structure of the table would be something like this:
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(10) | NO | PRI | NULL | |
| que | varchar(50) | YES | | NULL | |
| idcosa | int(10) | YES | | NULL | |
| 1 | varchar(200)| YES | | NULL | |
| 2 | varchar(200)| YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
idcosa I bring it from another table and it is a number to identify where it comes from, but that number keeps it well.
The fact is that for some reason as data2 has more than one value does not work and I do not know what I have wrong: _ (