Ver Mensaje Individual
  #11 (permalink)  
Antiguo 11/05/2011, 08:52
mogurbon
 
Fecha de Ingreso: enero-2011
Ubicación: DF
Mensajes: 898
Antigüedad: 13 años, 2 meses
Puntos: 155
Respuesta: como hago un Select dependiente de BD

Bueno pues te dejo aqui la liga del framework de ajax que uso y la forma en que se implementaria lo que quieres , solo es cosa de dar bien las rutas hacia la libreria

http://www.xajax-project.org/en/home/


Código PHP:
Ver original
  1. <?
  2. require_once("xajax_core/xajax.inc.php");#en donde se encuentra tu xajax
  3.  
  4. $xajax = new xajax();
  5. $xajax->registerFunction("myFunction");
  6. function myFunction($afiliadora){
  7.     $newContent='';
  8.     $newContent.='<select name="regimen" style="width:160">';
  9.     $newContent.='<option value=0>Regimen</option>';
  10.  
  11.     $res = mysql_query("SELECT id_regimen, regimen FROM regimenes where id_afiliadora=$afiliadora ORDER BY regimen");
  12.     while($rw = mysql_fetch_array($res)){
  13.         $newContent.= '<option value="'.$rw['id_regimen'].'">';
  14.         $newContent.=    $rw['regimen'];
  15.         $newContent.= "</option>";
  16.     }
  17.     $newContent.='</select>';
  18.     $objResponse = new xajaxResponse();
  19.     $objResponse->assign("regimen","innerHTML", $newContent);
  20. }
  21. $xajax->processRequest();
  22. ?>
  23.  
  24. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  25. <html xmlns="http://www.w3.org/1999/xhtml">
  26. <head>
  27. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  28. <title>Documento sin t&iacute;tulo</title>
  29. <?php $xajax->printJavascript(); #aqui como parametro debes poner la ruta de la carpeta de xajax?>
  30.  
  31. </head>
  32.  
  33. <body>
  34. <form id="form1" name="form1" method="post">
  35. <div id=dependiente>
  36.  
  37. <!--Combo principal-->
  38. <select name="afiliadora" onchange="xajax_myFunction(this.options[this.selectedIndex].value);" style='width:200px'>
  39. <option value=0>Afiliadoras</option>
  40. <?
  41.  
  42.    $res = mysql_query("SELECT id_afiliadora, afiliadora FROM afiliadoras ORDER BY afiliadora");
  43.     while($rw = mysql_fetch_array($res)){
  44.         echo "<option value='".$rw['id_afiliadora']."' >";      
  45.         echo    $rw['afiliadora'];
  46.         echo "</option>";
  47.     }
  48.  
  49. ?>
  50. </select>
  51.  
  52. <div id="regimen">
  53.     <select name="regimen" style='width:200px'>
  54.     <option value=0>Regimen</option>
  55.     </select>
  56. </div>
  57. </form>
  58. </body>
__________________
No me interesan ni las gracias ni los karmas , pero si que se genere conocimiento, si se dio con la respuesta por favor confirmalo