Ver Mensaje Individual
  #4 (permalink)  
Antiguo 21/08/2014, 12:41
marcelocuiza_de
 
Fecha de Ingreso: abril-2013
Mensajes: 60
Antigüedad: 11 años, 1 mes
Puntos: 2
Respuesta: Como hacer varios insert a la vez?

bueno, lo q te recomendaría
1.-cambiar los nombres a tus inputs, de tal manera que estos sean arrays

<tr>
<th scope="row"><label for="<?php echo $i ?>"><?php echo $i ?></label></th>
<td><input type="text" name="fecha[]" style="width: 80%" id="f1" />
<img src="../ima/calendario.png" width="16" height="16" border="0" title="f1" id="lanzador" /> </td>
<td><input type="text" name="problema[]" /></td>
<td> <input type="text" name="plantas[]" /> </td>
<td><input type="text" name="producto[]" /> </td>
<td><input type="text" name="dosis[]" /> </td>
<td><input type="text" name="cantidad[]" /> </td>
<td><input type="text" name="reporte[]" /></td>
</tr>

2.- usar un bucle (for,while,...) para repetir tus rows de manera dinamica

<?php for($i=0,$i<4;$i++){ ?>
<tr>
<th scope="row"><label for="<?php echo $i ?>"><?php echo $i ?></label></th>
<td><input type="text" name="fecha[]" style="width: 80%" id="f1" />
<img src="../ima/calendario.png" width="16" height="16" border="0" title="f1" id="lanzador" /> </td>
<td><input type="text" name="problema[]" /></td>
<td> <input type="text" name="plantas[]" /> </td>
<td><input type="text" name="producto[]" /> </td>
<td><input type="text" name="dosis[]" /> </td>
<td><input type="text" name="cantidad[]" /> </td>
<td><input type="text" name="reporte[]" /></td>
</tr>
<?php } ?>

3.- en tu archivo donde recives los datos, estos llegarían dentro un array, por lo tanto el insert estaria dentro un bucle.

$nombreCabo = $_POST['nombre'];
$fecha = $_POST['fecha'];
$problema = $_POST['problema'];
$plantas = $_POST['plantas'];
$producto = $_POST['producto'];
$dosis = $_POST['dosis'];
$cantidad = $_POST['cantidad'];
$reporte = $_POST['reporte'];
$vivero = $_POST['vivero'];

foreach($fecha as $key => $value){

$insertar = mysql_query("INSERT INTO reporte_cabo
(nombre_cabo,fecha_cabo,problema,planta_tratadas,p roducto_correctivo,dosis_correctivo,
cantidad,reporte_cabocol,id_vivero)
VALUES
('$nombreCabo','".$fecha[$key]."','".$problema[$key]."','$plantas[$key]."', '".$producto[$key]."','".$dosis[$key]."','".$cantidad[$key]."','".$reporte[$key]."','".$ vivero[$key]."'),

}


esa es la idea...
espero sirva, salu2