Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/06/2009, 09:26
Avatar de Huacho12
Huacho12
 
Fecha de Ingreso: septiembre-2008
Ubicación: Isla Mujeres Q. Roo
Mensajes: 175
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: input insercion multiple en un for

Hola!!!!

Wille.

Supongo que la pagina a donde mandas tu txcertificacion es la misma, entonces lo que tendrias que hacer es lo siguientes:

<?php

$txcertificacion = $_POST["txcertificacion"]; //RECIBO EL VALOR DEL TXCERTIFICACION QUE ES EL QUE VA A DECIR CUANTAS VECES QUIERO QUE SE REPITA MI IMPUT
//$txcertificacion=$_POST['txcertificacion'];

?>
<form id="form1" name="form1" method="post" action="for.php">
<table width="200" border="0">
<tr>
<td width="108"><h3># de Modulos</h3></td>
<td width="174"><label>
<input type="text" name="txcertificacion" id="txcertificacion" value="<?php echo "".$txcertificacion; //RECUPERO EL VALOR ?>" />
</label></td>
<td width="66"><label>
<input type="submit" name="button" id="button" value="Enviar" />
</label></td>
</tr>

<?php

for($i=0;$i<$txcertificacion;$i++) { //Con este for repito el numero de veces que haya puesto en el imput
?>

<tr>
<td colspan="2"><label>Nombre del modulo</label></td>

<td><input name="nombre" type="text" id="nombre" value="" size="60" /></td>

<td><?php echo "nombre $i"; ?></td>

<td><?php //echo"".$n." <p>&nbsp;</p>" ?></td>

</tr>

<?php
}
?>

</table>
<table width="200" border="0">
<tr>
<td width="108"><h3>&nbsp;</h3></td>
<td width="174"><label></label></td>
<td width="66"><label>
<input type="submit" name="button2" id="button2" value="Guardar" onclick="ejemplo_v1.php;" />
</label></td>
</tr>
</table>

</form>

Y para insetar:

$misdatos=split(",",$_POST["nombre"]);//RECUPERO LOS DATOS DEL VECTOR
$cont=count($misdatos);//CUENTO LA LONGITUD DEL VECTOR

for($i=0;$i<$cont;$i++)
{
mysql_query("insert tuTabla values (campo1,campo2,campo3,$misdatos[$i])",$tuConexion);
}

Espero te pueda servir este codigo.
Espero tus comentarios.
Saludos.