@helacer, creo que lo he entendido, tengo este código y me funciona, te ganaste Karma amigo:
consulta.php:
Código PHP:
<html>
<body>
<form method = "post" action = "mostrar.php">
<table>
<tr>
<td>Producto</td>
<td>Cantidad</td>
</tr>
<?php
$link = mysql_connect("localhost", "user", "0000");
mysql_select_db("Prueba", $link);
$result = mysql_query("select * from Productos", $link);
while ($registro = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$registro['Descripcion']."</td>";
echo "<td><input type ='text' name = 'Cantidad_".$registro['Codigo']."'></td>";
echo "</tr>";
}
?>
</table>
<input type="Submit" name = "enviar" value = "Mostrar">
</body>
</html>
mostrar.php:
Código PHP:
<?php
// Carga los productos
$link = mysql_connect("localhost", "user", "0000");
mysql_select_db("Prueba", $link);
$Select = mysql_query("select * from Productos");
// Recorro los productos
while ($Recorre = mysql_fetch_array($Select)) {
// Genera el nombre del campo
$Actual = "Cantidad_".$Recorre['Codigo'];
// Recibe la cantidad asignada al producto actual
$Cantidad = $_POST[$Actual];
if ($Cantidad > 0)
// Inserta el pedido
echo "Nombre de la caja de texto: ".$Actual." Código: ".substr($Actual, 9, strlen($Actual))." Cantidad: ".$Cantidad."<br/>";
//$Agrega = mysql_query("insert into pedidos values ('".$CodPedido."','".$Recorre['Codigo']."','".$Cantidad."')");
if ($Agrega)
echo "Se agregó el producto al pedido";
}
?>
Saludos.