Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/05/2013, 20:15
ghost_darknet
 
Fecha de Ingreso: mayo-2012
Ubicación: shilito
Mensajes: 67
Antigüedad: 12 años, 10 meses
Puntos: 3
Respuesta: Realizar consulta sql con valores de un arreglo

naciostars, aquí va el código completo desde el inicio de la pagina (con javascript) para después pasarla con php a otro que hace solo una consulta a la base de datos y extraigo la información.


Código PHP:
Ver original
  1. <?php
  2. include"../../validacion/sesion_valida.php";
  3. include"../../validacion/conexion.php";
  4. include"querys.php"
  5.  
  6. ?>
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <title>Plataforma Control Inventario</title>
  12.  
  13. <script src="agregar.js" language="JavaScript"> </script>
  14. <script>
  15. function validador(){
  16.     var desde = document.getElementById("desde").value
  17.     var hasta = document.getElementById("hasta").value;
  18.    
  19.     if(desde ==""){
  20.         alert("Tiene que seleccionar un valor en el campo DESDE de la serie ");
  21.         return;
  22.     }
  23.    
  24.     if(hasta ==""){
  25.         alert("Tiene que seleccionar un valor en el campo HASTA");
  26.         return;
  27.     }
  28.        
  29.     document.getElementById("form1").submit();
  30. }
  31. </script>
  32.  
  33. <link href="../estilos/default.css" rel="stylesheet" type="text/css" />
  34. </head>
  35. <body>
  36. <div id="contenedor-principal">
  37.  
  38. <h1 class="titulo-mostrar">Control </h1>
  39.  
  40. <h2 class="titulo">Modulo de Control</h2>
  41.  
  42. <h5 class="caja-izquierda"><a href="../menu.php">Volver</a><span class="forma"></span></h5>
  43. <hr />
  44. <br />
  45.  
  46. <h4 class="sub-titulo">Modulo de Despacho </h4>
  47. <br />
  48.  
  49. <form action="previa_despacho.php" method="post" enctype="application/x-www-form-urlencoded" target="_self">
  50.  
  51. <h5 class="titulo">Informacion Requerida para el env&iacute;o Equipamiento</h5>
  52.  
  53. <table class="tabla">
  54. <tr>
  55. <th class="relleno">Ticket</th> <th class="relleno">Tenico</th> <th class="relleno">Validado Por</th>
  56. <th class="relleno">Desde</th> <th class="relleno">Desde</th>
  57. </tr>
  58. <tr>
  59. <td><input type="text" name="ticket" id="ticket" autocomplete="off" size="14" /></td>
  60. <td><input type="text" name="revisado" required="required" id="revisado" autocomplete="off" size="30" /></td>
  61. <td><input type="text" name="validador" id="validador" required="required" autocomplete="off" size="30" /></td>
  62. <td><label for="desde"></label>
  63.   <select name="desde" id="desde" class="dropb">
  64.   <option value="">Seleccione Origen</option>
  65.     <?php $info_origen1 = mssql_query ($desde,$conexion);
  66.         while ($show_origen1= mssql_fetch_array($info_origen1)){
  67.      ?>
  68.      <option class="formato-option" value="<?php echo $show_origen1['0']?>"><?php echo $show_origen1['1']?></option>
  69.     <?php } ?>
  70.       </select></td>
  71. <td><label for="hasta"></label>
  72.   <select name="hasta" id="hasta" class="dropb">
  73.   <option value="">Seleccione Destino</option>
  74.     <?php $info_hasta1 = mssql_query ($hasta,$conexion);
  75.         while ($show_hasta1= mssql_fetch_array($info_hasta1)){
  76.      ?>
  77.      <option class="formato-option" value="<?php echo $show_hasta1['0']?>"><?php echo $show_hasta1['1']?></option>
  78.     <?php } ?>
  79.       </select></td>
  80.  
  81. </tr>
  82.  
  83. </table>
  84.  
  85. <br />
  86. <!--<h5 class="titulo">Ingrese los datos  del Hardware</h5>-->
  87.  
  88. <fieldset id="fiel"><input type="button" value="Agregar Hardware" onclick="crear(this)" /></fieldset></th>
  89.  
  90. <br />
  91.  
  92. <div id="centra-tabla">
  93. <table class="tabla">
  94. <tr> <th> <input type="submit" name="submit_asignacion" id="submit_asignacion" value="Validar Informacion" /> </th></tr>
  95.  
  96. </div>
  97. </form>
  98.  
  99. </div>
  100. </body>
  101. </html>

Codigo java script que me repite el input es el siguiente

Código Javascript:
Ver original
  1. num=0;
  2.  
  3. function crear(obj) {
  4.   num++;
  5.   fi = document.getElementById('fiel'); // 1
  6.   contenedor = document.createElement('div'); // 2
  7.   contenedor.id = 'div'+num; // 3
  8.   fi.appendChild(contenedor); // 4
  9.  
  10.   ele = document.createElement('input'); // 5
  11.   ele.type = 'text'; // 6
  12.   ele.name = 'serie[]'; // 6
  13.   ele.autocomplete = 'off'; // 6
  14.   ele.placeholder = 'Serie del Equipo'; // 6
  15.   ele.size = '25';
  16.   ele.required = 'required';
  17.   contenedor.appendChild(ele); // 7
  18.  
  19.  
  20.   ele = document.createElement('input'); // 5
  21.   ele.type = 'button'; // 6
  22.   ele.value = 'Borrar'; // 8
  23.   ele.name = 'div'+num; // 8
  24.   ele.onclick = function () {borrar(this.name)} // 9
  25.   contenedor.appendChild(ele); // 7
  26. }
  27. function borrar(obj) {
  28.   fi = document.getElementById('fiel'); // 1
  29.   fi.removeChild(document.getElementById(obj)); // 10
  30. }
  31.  
  32. function borraDesasignacion(obj) {
  33.   fi = document.getElementById('desasignacion'); // 1
  34.   fi.removeChild(document.getElementById(obj)); // 10
  35. }


y Aqui va el php que toma los datos y para mostrar los datos de la serie ingresada

Código PHP:
Ver original
  1. <?php
  2. include"../../validacion/sesion_valida.php";
  3. include"../../validacion/conexion.php";
  4. include"querys.php";
  5.  
  6.  
  7.  
  8. $revisado = strtoupper(filter_input(INPUT_POST, 'revisado',FILTER_SANITIZE_STRING));
  9. $validado = strtoupper(filter_input(INPUT_POST, 'validador',FILTER_SANITIZE_STRING));
  10. $ticket = strtoupper(filter_input(INPUT_POST, 'ticket',FILTER_SANITIZE_STRING));
  11. $desde = strtoupper(filter_input(INPUT_POST, 'desde',FILTER_SANITIZE_STRING));
  12. $hasta = strtoupper(filter_input(INPUT_POST, 'hasta',FILTER_SANITIZE_STRING));
  13.  
  14. $series = $_POST['serie'];
  15.  
  16. $genera_lote = mssql_query($nun_lote,$conexion);
  17. while($lote_numero = mssql_fetch_array($genera_lote)){
  18.     $numero = $lote_numero['0'];
  19. }
  20.  
  21. //$series = array();
  22. //phpinfo();
  23.  
  24. $cantidad =  count($series);
  25.  
  26. while($show_info = mssql_fetch_array()){
  27.     echo $show_info['0'];
  28. }
  29.  
  30.  
  31. $cont= $cantidad;
  32. echo $cantidad."<br>";
  33.  
  34. $i=0;
  35. while ($i<$cont) {
  36.     //$cadena="";
  37.     $cadena= $query_equipo.$series[$i];
  38.     echo $cadena."<br>";
  39.     $consulta_cadena = mssql_query($cadena,$conexion);
  40.     echo "cadena".$consulta_cadena."<br>";
  41.      $i=$i+1;
  42. }
  43.  
  44.  
  45. ?>
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  47. <html xmlns="http://www.w3.org/1999/xhtml">
  48. <head>
  49. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  50. <title>Plataforma Control de Inventario</title>
  51. <link href="../estilos/default.css" rel="stylesheet" type="text/css" />
  52. </head>
  53.  
  54. <body>
  55. <div id="contenedor-principal">
  56.  
  57. <h1 class="titulo-mostrar">Control </h1>
  58.  
  59. <h3 class="titulo">Modulo de Despacho </h3>
  60.  
  61. <h5 class="caja-izquierda"><a href="../menu.php">Volver al Menu</a><span class="forma"></span></h5>
  62. <hr />
  63. <br />
  64. <h5 class="titulo">Informacion del Hardware para ser enviado a la Correctiva</h5>
  65.  
  66. <form action="envio_reparacion.php" name="form1" enctype="application/x-www-form-urlencoded" id="form1" target="_self" method="post" >
  67. <div id="centra-tabla">
  68.  
  69. <table class="tabla">
  70. <tr>
  71. <th class="relleno">Tipo</th> <th class="relleno">Serie</th> <th class="relleno">Rotulo</th> <th class="relleno">Modelo</th> <th class="relleno">Num Lote</th> <th class="relleno">Fecha</th> <th class="relleno">Estado</th> <th class="relleno">Desde</th>
  72. <th class="relleno">Hasta</th> <th class="relleno">Validado por</th> <th class="relleno">Revisado por</th>
  73. </tr>
  74.  
  75. <?php
  76. if (!empty($serie1)){
  77. $query_equipo1 = $query_equipo."'".$serie1."'";
  78. $consulta_equipo1 = mssql_query($query_equipo1,$conexion);
  79.  
  80. while($info_equipo1 = mssql_fetch_array($consulta_equipo1)){  ?>
  81. <tr>
  82. <td><input type="text" name="tipo[]" id="tipo" value="<?php echo $info_equipo1['0'] ?>" size="11" readonly="readonly" /></td>
  83. <td><input type="text" name="serie[]" id="serie" value="<?php echo $info_equipo1['1'] ?>" size="14" readonly="readonly" /></td>
  84. <td><input type="text" name="rotulo[]" id="rotulo" value="<?php echo $info_equipo1['2'] ?>"  size="14" readonly="readonly" /></td>
  85. <td><input type="text" name="modelo[]" id="modelo1" value="<?php echo $info_equipo1['3'] ?>" size="22" readonly="readonly" /></td>
  86. <td><input type="text" name="num_lote[]" value="<?php echo $numero ?>"  size="7" id="num_lote1" readonly="readonly" /></td>
  87. <td><input type="text" name="fecha[]" id="fecha" value="<?php echo $info_equipo1['4'] ?>"  size="23" readonly="readonly" /></td>
  88. <td><input type="text" name="estado[]" size="18" value="<?php echo $info_equipo1['5'] ?>" id="estado" readonly="readonly" /></td>
  89. <td><input type="text" name="validado" readonly="readonly" value="<?php echo $validado ?>" size="23" /></td>
  90. <td><input type="text" name="revisado" readonly="readonly" value="<?php echo $revisado ?>" size="23" /></td>
  91.  
  92. </tr>
  93. <?php }//cierro while equipo
  94. }?>
  95. </table>
  96.  
  97. <table class="tabla">
  98. <<tr><th><br /></th>
  99. <th> <input type="button" value="Despachar Hardware" onclick="validador()" /></th></tr>
  100. </table>
  101. </div>
  102.  
  103. </form>
  104.  
  105. </div>
  106. </body>
  107. </html>