Ver Mensaje Individual
  #13 (permalink)  
Antiguo 11/05/2011, 11:13
kosios
 
Fecha de Ingreso: marzo-2009
Mensajes: 90
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: como hago un Select dependiente de BD

Cita:
HOla amigo mira yo he hecho este pero no me funciona de esta manera es q lo necesito. veras no solo es q los listes dependiente mente en el combobox, sino tambien q cuando intente guardarlo insert en una nueva tabla llamada REMISIONES q contiene los campos de nom_afiliadora y regimen, no me guarde el ID sino los valores realies como por ejemplo, nom_afiliadora CONSALTRA, SRAGON, BREMA etc....REGIMENES CONTRIBUTIVO, SOAP etc....Y no q me guarde los id q es lo q me esta pasando.......ESTE Q LES MUESTRO AQUI NO ME funciona no hace nada. pero tiene la logica de lo q quiero.


Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.         <title>Selects dependientes con jQuery.</title>
  6.         <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
  7.         <script language="JavaScript" type="text/JavaScript">
  8.             $(document).ready(function(){
  9.                 $("#select1").change(function(event){
  10.                     var id = $("#select1").find(':selected').val();
  11.                     $("#select2").load('genera-select.php?id='+id);
  12.                 });
  13.             });
  14.         </script>
  15.     </head>
  16.  
  17.     <body>
  18.         <form>
  19.        
  20.         <?php
  21.         include("../../PHP/getconfi_conect.php");
  22.  
  23.  $sql = ("SELECT regimen, id_regimen FROM regimenes order by regimen");
  24.    $resultado=mysql_query($sql);
  25.   if ($row = mysql_fetch_array($resultado)){
  26.       ?>    <div class="tipo" align="left">  <select name="select1" id="select1">
  27.       <option value="">[Seleccione]</option>
  28.       <?php
  29. do {
  30.        echo '<option value= "'.$row["regimen"].'">'.$row["regimen"].'</option>';
  31. } while ($row = mysql_fetch_array($resultado));
  32. ?>
  33.     </select>      <?php } ?>  </div>
  34.            
  35.                <br />
  36.                
  37.             <select name="select2" id="select2">
  38.  
  39.             </select>
  40.         </form>
  41.     </body>
  42. </html>
  43.  
  44.  
  45. otro archivo php llamado genera-select.php
  46.  
  47. <?php
  48. include("../../PHP/getconfi_conect.php");
  49.  
  50. $consulta = "SELECT nom_afiliadora, n_regimen from  entidades_afiliadoras
  51.             WHERE n_regimen = ".$_GET['id'];
  52. $query = mysql_query($consulta);
  53. while ($fila = mysql_fetch_array($query)) {
  54.     echo '<option value="'.$fila['nom_afiliadora'].'">'.$fila['nom_afiliadora'].'</option>';
  55. };
  56.  
  57. ?>