Ver Mensaje Individual
  #14 (permalink)  
Antiguo 21/08/2013, 16:29
gilihio
 
Fecha de Ingreso: agosto-2013
Ubicación: hermosillo
Mensajes: 13
Antigüedad: 10 años, 8 meses
Puntos: 0
Respuesta: Insertar registros desde una tabla dimacia con select dentro de ella

y este es mi código que use para el programa que estoy utilizando

Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     include_once "Conexion.php";  
  4. ?>
  5. <html>
  6.     <head>
  7.         <title>Login</title>
  8.     </head>
  9.  
  10.     <body bgcolor="#AAD9D7">
  11.        
  12.         <form action="Cerrar.php" method="post">
  13.           <table width="100%">
  14.             <tr>
  15.               <td>Usuario: <?php echo $_SESSION['usuario'].' '; echo ' Fecha: '; echo date("d-m-Y"); ?></td>
  16.               <td align="right"><input name="logout" value="Cerrar sesion" type="submit"></td>
  17.             </tr>
  18.           </table>
  19.         </form>
  20.        
  21.         <table>
  22.           <tr>
  23.             <td><form action="Tabla.php" method="post"><input type="submit" value="Tabla"></form></td>
  24.             <td><form action="Buscar.php" method="post"><input type="submit" value="Buscar"></form></td>
  25.             <td><form action="Edit.php" method="post"><input type="submit" value="Modificar"></form></td>
  26.           </tr>
  27.         </table>
  28.        
  29.         <form method="post">
  30.             <table>
  31.                 <tr>
  32.                     <td>Trailer
  33.                         <select name="compania">
  34.                             <option value="T13-">T 13 -</option>
  35.                             <option value="I13-">I 13 -</option>
  36.                         </select>
  37.                         <input type="text" name="tnumero" maxlength="6">&nbsp;&nbsp;Comentario<input type="text" size="30" name="ccomentario">
  38.                     </td>
  39.                 </tr>
  40.             </table>
  41.            
  42.             <table bgcolor="#7AC7CD" border="1" cellpadding="1" cellspacing="0" align="left">
  43.                 <tr>
  44.                     <th colspan="8">Tipos de incidencias</th>
  45.                 </tr>
  46.                                    
  47.                 <tr>
  48.                     <td>Incidencia</td>
  49.                     <td>Subincidencia</td>
  50.                     <td>Responsable</td>
  51.                     <td><input type="submit" name="benviar"></td>
  52.                 </tr>
  53.                    
  54.                 <tr>
  55.                     <?php
  56.                         $consulta = mysql_query('SELECT t2.incidencias, t3.idtabla3, t3.subincidencia FROM tabla3 AS t3 INNER JOIN tabla2 AS t2 ON t3.idtabla2 = t2.idtabla2 ORDER BY t2.idtabla2');
  57.                         while($result = mysql_fetch_array($consulta)):
  58.                         $subi=$result['1'];
  59.                         $sub[]=$subi;
  60.                     ?>                     
  61.                     <td><div><?php echo $result['0'] ?></div></td>
  62.                     <td><div><?php echo $result['2'] ?></div></td>
  63.                     <td><div><?php 
  64.                                 $consultausuario='select * from tabla4 order by nombre';
  65.                                 $resultado_de_consulta=mysql_query($consultausuario);
  66.                                 echo "<select name='lresponsable[]'>";
  67.                                 echo "<option>nada</option>";
  68.                                 while($fila=mysql_fetch_array($resultado_de_consulta))
  69.                                 {
  70.                                     echo "<option value='".$fila['2']."'>".$fila['2']."</option>";
  71.                                 }
  72.                                 echo "</select>";
  73.                             ?>
  74.                     </div></td>
  75.                     <td><div><input type="checkbox" name="datos[]" value="<?php echo $result['idtabla3']?>"</div></td>
  76.                 </tr>
  77.                        
  78.                         <?php
  79.                         endwhile; ?>
  80.             </table>
  81.         </form>
  82.        
  83.         <?php                      
  84. //valida que al presionar el boton se ejecute todo
  85.             if(isset($_POST['benviar']))
  86.             {
  87. //query para tomar numero maximo de repote y asi incrementar 1
  88.  
  89.                 //$query= mysql_query("SELECT MAX(numero_reporte) AS id FROM tabla1");
  90.                 //if ($row = mysql_fetch_row($query))
  91.                 //{
  92.                 //  $id = trim($row[0]);
  93.                 //}
  94. //variables            
  95.                 //$numero_reporte=$id+1;                                        //creara un numero de reporte para que a cada uno le guarde el mismo numero de reporte
  96.                 $usuario=$_SESSION['usuario'];                              //se almacena el nombre con el cual el usuario inicio sesion
  97.                 $compania=strtoupper($_POST['compania']);                   //compañia de trailer
  98.                 $numero=str_pad($_POST['tnumero'],6,"0",STR_PAD_LEFT);      //se rellena el espacio restante
  99.                 $trailer=array("$compania","$numero");                      //se guarda la compañia y el numero de trailer
  100.                 $comentario=strtoupper($_POST['ccomentario']);              //campo de comentario
  101.                 $data=$_POST['datos'];                                      //arreglo que contara las veces que el usuario selecciona una casilla
  102.                 $responsable=$_POST['lresponsable'];                        // se refiere a la lista desplegable del responsable
  103.                 $i=0;                                                       //incrementador
  104.                 $cont=count($data);                                         //cuenta el maximo de datos del arreglo $data
  105. //validaciones             
  106.                 for($i=0; $i<21; $i++)
  107.                 {
  108.                     if($responsable[$i]!='nada')
  109.                     {
  110.                         mysql_query("INSERT INTO tabla1 (idtabla3,trailer,usuario_inicial,fecha_inicial,comentario_inicial,responsable) values ('$sub[$i]','$trailer[0]$trailer[1]','$usuario',NOW(),'$comentario','$responsable[$i]')");
  111.                     }
  112.                 }
  113.             }      
  114.            
  115.         ?>
  116.     </body>
  117. </html>