Ver Mensaje Individual
  #30 (permalink)  
Antiguo 22/01/2013, 17:07
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Consulta de Campos en tablas.

Cita:
Iniciado por GatorV Ver Mensaje
Pues no porque estas leyendo los valores de $_POST, como $_POST['local'] etc, tienes que usar las variables locales que estas definiendo dentro del for...

Me pregunto si realmente estas tratando de entender lo que te estoy explicando, o solo haciendo copy/paste sin entender...
Vuelve a perdonarme, ya te avise que era novato. Esto queda tal que así:

Código HTML:
Ver original
  1. <div id="TabbedPanels2" class="TabbedPanels">
  2.             <ul class="TabbedPanelsTabGroup">
  3.               <li class="TabbedPanelsTab" tabindex="0">Dirección</li>
  4.               <li class="TabbedPanelsTab" tabindex="0">Dirección 2</li>
  5.               <li class="TabbedPanelsTab" tabindex="0">Dirección 3</li>
  6.             </ul>
  7.             <div class="TabbedPanelsContentGroup">
  8.               <div class="TabbedPanelsContent">
  9.               <table width="100%">
  10.                   <tr>
  11.                     <th scope="col">Calle</th>
  12.                     <input name="NUM_DIR[]" type="hidden" size="" value="1" />
  13.                     <th scope="col"><input name="calle[]" type="text" size="30"value="" /></th>
  14.                     <th scope="col"></th>
  15.                     <th scope="col"><input name="numero[]" type="text" size="1"value="" />
  16.                     EDF
  17.                     <input name="edificio[]" type="text" size="1"value="" />
  18.                     PTA
  19.                     <input name="puerta[]" type="text" size="1"value="" />
  20.                     PISO
  21.                     <input name="piso[]" type="text" size="1"value="" />
  22.                     LTA
  23.                     <input name="letra[]" type="text" size="1"value="" /></th>
  24.                 </tr>
  25.                      <tr>
  26.                     <th scope="col">Localidad</th>
  27.                     <th scope="col"><input name="localidad[]" type="text" size="30" value="" /></th>
  28.                     <th scope="col">Provincia</th>
  29.                     <th scope="col"><input name="provincia[]" type="text" size="30" value="" /></th>
  30.                   </tr>
  31.                   <tr>
  32.                   <th scope="col">Email</th>
  33.                     <th scope="col"><input name="email[]" type="text" size="30" value=""/></th>
  34.                 </tr>
  35.               </table>
  36.               </div>
  37.               <div class="TabbedPanelsContent">
  38.                <table width="100%">
  39.                   <tr>
  40.                     <th scope="col">Calle</th>
  41.                     <input name="NUM_DIR[]" type="hidden" size="" value="2" />
  42.                     <th scope="col"><input name="calle[]" type="text" size="30"value="" /></th>
  43.                     <th scope="col"></th>
  44.                     <th scope="col"><input name="numero[]" type="text" size="1"value="" />
  45.                     EDF
  46.                     <input name="edificio[]" type="text" size="1"value="" />
  47.                     PTA
  48.                     <input name="puerta[]" type="text" size="1"value="" />
  49.                     PISO
  50.                     <input name="piso[]" type="text" size="1"value="" />
  51.                     LTA
  52.                     <input name="letra[]" type="text" size="1"value="" /></th>
  53.                 </tr>
  54.                      <tr>
  55.                     <th scope="col">Localidad</th>
  56.                     <th scope="col"><input name="localidad[]" type="text" size="30" value="" /></th>
  57.                     <th scope="col">Provincia</th>
  58.                     <th scope="col"><input name="provincia[]" type="text" size="30" value="" /></th>
  59.                   </tr>
  60.                   <tr>
  61.                   <th scope="col">Email</th>
  62.                     <th scope="col"><input name="email[]" type="text" size="30" value=""/></th>
  63.                 </tr>
  64.               </table>
  65.               </div>
  66.               <div class="TabbedPanelsContent">
  67.                <table width="100%">
  68.                   <tr>
  69.                     <th scope="col">Calle</th>
  70.                     <input name="NUM_DIR[]" type="hidden" size="" value="3" />
  71.                     <th scope="col"><input name="calle[]" type="text" size="30"value="" /></th>
  72.                     <th scope="col"></th>
  73.                     <th scope="col"><input name="numero[]" type="text" size="1"value="" />
  74.                     EDF
  75.                     <input name="edificio[]" type="text" size="1"value="" />
  76.                     PTA
  77.                     <input name="puerta[]" type="text" size="1"value="" />
  78.                     PISO
  79.                     <input name="piso[]" type="text" size="1"value="" />
  80.                     LTA
  81.                     <input name="letra[]" type="text" size="1"value="" /></th>
  82.                 </tr>
  83.                      <tr>
  84.                     <th scope="col">Localidad</th>
  85.                     <th scope="col"><input name="localidad[]" type="text" size="30" value="" /></th>
  86.                     <th scope="col">Provincia</th>
  87.                     <th scope="col"><input name="provincia[]" type="text" size="30" value="" /></th>
  88.                   </tr>
  89.                   <tr>
  90.                   <th scope="col">Email</th>
  91.                     <th scope="col"><input name="email[]" type="text" size="30" value=""/></th>
  92.                 </tr>
  93.               </table>
  94.               </div>


Código PHP:
Ver original
  1. }
  2. $id_aviso=$_POST['id_aviso'];
  3. $localidad = $_POST['localidad'];
  4. $provincia= $_POST['provincia'];
  5. $calle = $_POST['calle'];
  6. $numero = $_POST['numero'];
  7. $edificio= $_POST['edificio'];
  8. $puerta = $_POST['puerta'];
  9. $piso = $_POST['piso'];
  10. $letra= $_POST['letra'];
  11. $email = $_POST['email'];
  12. $NUM_DIR = $_POST['NUM_DIR'];
  13. $total = count($localidad);
  14. for ($i = 0; $i < $total; $i++) {
  15.         $local = $localidad[$i];
  16.         $prov = $provincia[$i];
  17.         $call = $calle[$i];
  18.         $nume = $numero[$i];
  19.         $edif = $edificio[$i];
  20.         $puer = $puerta[$i];
  21.         $pis = $piso[$i];
  22.         $letr = $letra[$i];
  23.         $emai = $email[$i];
  24.         $NUM_D = $NUM_DIR[$i];
  25.  
  26.    $insertSQL = sprintf("INSERT INTO dir_usuarios (localidad,provincia,calle,numero,edificio,puerta,piso,letra,email,id_aviso,NUM_DIR)VALUES ('$local', '$prov', '$call', '$nume', '$edif','$puer','$pis','$letr', '$emai', '$id_aviso', '$NUM_D')",
  27.                        GetSQLValueString($_POST['localidad'], "text"),
  28.                        GetSQLValueString($_POST['provincia'], "text"),
  29.                        GetSQLValueString($_POST['calle'], "text"),
  30.                        GetSQLValueString($_POST['numero'], "text"),
  31.                        GetSQLValueString($_POST['edificio'], "text"),
  32.                        GetSQLValueString($_POST['puerta'], "text"),
  33.                        GetSQLValueString($_POST['piso'], "text"),
  34.                        GetSQLValueString($_POST['letra'], "text"),
  35.                        GetSQLValueString($_POST['email'], "text"),
  36.                        GetSQLValueString($_POST['id_aviso'], "int"),
  37.                        GetSQLValueString($_POST['NUM_DIR'], "int"));
  38.  
  39. mysql_select_db($database_conexion, $conexion);
  40. $dir_usuarios = mysql_query($insertSQL, $conexion) or die(mysql_error());
  41. }


Una pregunta que quiero hacerte es que en un primer formulario que tengo donde ingreso los datos del cliente y luego recupero esos datos con un id autoincrement y vuelvo a ingresar los datos de la dirección con dicho id. Habitualmente se hace así o puedo hacerlo de otra forma mas rápida. Siempre tengo que hacer un INSERT detras de otro para poder sacar el id que las une no

PD:Gracias por no haberme hecho el código desde el principio