PHP - Insertar inputs dinámicos

 
Vista:

Insertar inputs dinámicos

Publicado por Rey Red (2 intervenciones) el 29/10/2018 18:48:32
Hola, amigos, soy un poco nuevo en esto, y tenía la duda de como insertar unos input dinamicos, el codigo que uso es el siguiente:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
if (!empty($productos))
{
    echo '<table class="table table-striped">';
    echo '
    <tr>

        <th>Partida</th>
        <th>Codigo</th>
        <th>Descripción</th>
        <th>Cantidad</th>
        <th>Precio Unitario</th>
        <th>SubTotal</th>
    </tr>
    ';
    $count = null;
    foreach ($productos as $producto)
    {
        $count++;
        echo "<tr>";
 
        echo "<td>";
        echo $producto->PartidaProducto;
        echo "</td>";
        echo "<td>";
        echo $producto->Codigo;
        echo "<input type='hidden'  id='codigo".$count."' value='".$producto->Codigo."'>";
        echo "</td>";
        echo "<td>";
        echo $producto->Descripcion;
        echo "</td>";
        echo "<td>";
        echo "<input type='text' size='8' id='peras".$count."' value='0' onChange='calculo(this.value,precio".$count.".value,subtotal".$count.",total,iva,monto);'>";
     echo "</td>";
 
        echo "<td>";
        echo "$".$producto->PUnitario;
 
        echo "<input type='hidden' id='precio".$count."' value='".$producto->PUnitario."'>";
        echo "</td>";
        echo "<td>";
        echo "$<input type='text' size='8' disabled='true' id='subtotal".$count."' value='0'>";
        echo "</td>";
 
    }
 
}
?>

En donde a través de una consulta creo una tabla con los datos, pero al momento de querer insertar esta tabla dinamica en un insert, no logro llegar a la solución.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Insertar inputs dinámicos

Publicado por xve (6935 intervenciones) el 29/10/2018 19:40:53
No me queda claro que quieres hacer... puedes intentar detallar un poco mas?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Frut Demon Jr
Val: 31
Ha aumentado su posición en 9 puestos en PHP (en relación al último mes)
Gráfica de PHP

Insertar inputs dinámicos

Publicado por Frut Demon Jr (11 intervenciones) el 01/11/2018 19:08:50
Hola brother , te dejo un ejemplo espero y sea lo que necesitas
Saludos
Djr


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="es" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>  Inputs Dinamicos </title>
  </head>
  <body>
<form class="" action="inputs_dinamicos.html" method="post">
 
<center><h2> Inputs Dinamicos</h2> </center>
 
<!-- SE CREA EL ENCABEZADO DE LA TABLA -->
 
<center>
<table border =1>
  <tr>
    <td> ID</td>
    <td> NOMBRE</td>
    <td> APELLIDO</td>
</tr>
<tr>
<?php
//SE HACE LA CONEXION A LA BASE DE DATOS
$server = "localhost";
$user ="root";
$psw="";
$db="dbhelps";
$conexion=@new mysqli ($server,$user,$psw,$db);
 
// SE VALIDA QUE LA CONEXION SE EFECTUE
if($conexion-> connect_error){
  die('Ups ! Sorry I cant Connect to the Database , Trouble -> ' . $conexion->connect_error);
}
 
// SE CREA UNA VARIABLE QUE TENDRA LA CONSULTA A LA TABLA
$SqlGetData="select tblnId as ID, tblnNAme as NOMBRE , tblLastName AS APELLIDO from tblnombres";
//SE EJECUTA LA CONSULTA
$ResultQuery=$conexion->query($SqlGetData);
 
// SE REVIA SI LA COLSUTA DEVUELVE AL MENOS UN REGISTRO
if ($ResultQuery->num_rows > 0) {
  // SI TRAE REGISTROS HACE UN ARREGLO Y LO VA RECORRIENDO CON EL WHILE
  while ($row = $ResultQuery->fetch_array(MYSQLI_ASSOC)) {
    // SE CREAN VARIABLES PARA IR ALMACENANDO LA INFORMACION QUE CONTENGA CADA REGISTRO
        $id=$row['ID'];
        $nombre=$row['NOMBRE'];
        $apellido=$row['APELLIDO'];
 
// SE CREA EL RESTO DEL CUERPO DE LA TABLA Y SE LE CONCATENAN LOS VALORES
 echo "
<td><Input type='text' name= $id value=$id></td>
<td><Input type='text' name= $nombre value=$nombre></td>
<td><Input type='text' name= $apellido value=$apellido></td>
</tr>
 ";
/* NOTA:
         POR CADA VUELTA QUE DE EL CICLO IRA AGREGANDO UNA FILA

*/
  }
     // UNA VEZ QUE TERMINA EL CICLO SE CIERRA LA TABLA
  echo "
  </table>
  </center>
  ";
}
   else {
     // SI NO EMCUENTRA REGISTROS SOLAMENTE IMPRIME UN MENSAJE
     echo "<center> <h2> No Se Encontraron Registros </h2> </center>";
   }
 
 
 
 
$conexion->close();
 ?>
 
</form>
  </body>
</html>

IDinamics
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar