Insertar datos de un Array en mysql
Publicado por Ramon (1 intervención) el 25/07/2018 09:28:55
Muy buenas ..
Este es mi formulario donde envío los id de registros ingresados ..
En esta pagina tomo los datos enviados
Este es el print que hace en pantalla el ingreso
Me ayudarian en :
Al momento de ingresarla solo me esta ingresando el ultimo dato del array para lo cual no deberia el deber ser es que me ingrese cada ID de registro con sus respectivos valores si chequeo uno o si chequeo 10 debe ser indiferente. de antemano Gracias
Este es mi formulario donde envío los id de registros ingresados ..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if(mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$datas[] = $row;
?>
<tbody>
<tr>
<td width='100px'><?php echo($row['cod_ingreso']); ?></td>
<td width='180px'><?php echo($row['nombre']); ?></td>
<td width='180px'><?php echo($row['apellido']); ?></td>
<td width='160px'><?php echo($row['cedula']); ?></td>
<td width='160px'><?php echo($row['fecha']); ?></td>
<td width='130px'><?php echo($row['nivel']); ?></td>
<td width='150px'><?php echo($row['empresa']); ?></td>
<td width='150px' align="center"><input type="checkbox" name="chekbox[]" value="<?php echo $row['cod_ingreso']; ?>"></td>
</tr>
<?php
En esta pagina tomo los datos enviados
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<pre>
<?php
print_r($_POST);
?>
</pre>
<?php
$fact = $_POST['num_fac'];
$estado = $_POST['estado_fac'];
// if ($_SERVER["REQUEST_METHOD"] == "POST") {
foreach($_POST['chekbox'] as $indice => $valor){
$valores = $_POST['chekbox'][$indice];
$count = count($valores);
for ($i = 0; $i < $count; $i++) {
// echo $numero[$i];
$string = "INSERT INTO facturacion (ingreso_cod, num_fac, estado_fac ) VALUES ";
$string.="('".$valores. "', '".$fact."', '".$estado."'),";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
Array
(
[chekbox] => Array
(
[0] => 2
[1] => 3
[2] => 4
)
[num_fac] => 3333
[estado_fac] => 44444
)
Al momento de ingresarla solo me esta ingresando el ultimo dato del array para lo cual no deberia el deber ser es que me ingrese cada ID de registro con sus respectivos valores si chequeo uno o si chequeo 10 debe ser indiferente. de antemano Gracias
Valora esta pregunta


0