Ver Mensaje Individual
  #7 (permalink)  
Antiguo 08/03/2017, 06:56
keivis
 
Fecha de Ingreso: julio-2013
Mensajes: 123
Antigüedad: 11 años, 8 meses
Puntos: 1
Respuesta: Select dependa de otro mysql php

tengo una sola tabla.
Código SQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `medicina` (
  2.   `codigo` VARCHAR(100) NOT NULL,
  3.   `medicamento` VARCHAR(150) NOT NULL,
  4.   `presentacion` VARCHAR(50) NOT NULL,
  5.   `fecha_elaboracion` VARCHAR(20) NOT NULL,
  6.   `fecha_vencimiento` VARCHAR(20) NOT NULL,
  7.   `lote` VARCHAR(50) NOT NULL,
  8.   `cantidad_recibida` VARCHAR(10) NOT NULL,
  9.   `observacion_adicional` VARCHAR(400) NOT NULL,
  10.   `medico` VARCHAR(150) NOT NULL
  11. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

mi index.

Código PHP:
Ver original
  1. <script>
  2.  
  3. function myFunction(str)
  4. {
  5. loadDoc("q="+str,"cdm/proc.php",function()
  6.   {
  7.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  8.     {
  9.     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  10.     }
  11.   });
  12. }
  13.  
  14. function myFunction2(str)
  15. {
  16. loadDoc("r="+str,"cdm/proc2.php",function()
  17.   {
  18.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  19.     {
  20.     document.getElementById("myDiv2").innerHTML=xmlhttp.responseText;
  21.     }
  22.   });
  23. }
  24.  
  25. </script>
  26. <?php
  27. include 'cdm/conexion.php';
  28. $con=conexion();
  29. $res=mysql_query("select * from medicina",$con);
  30.  
  31. ?>
  32. <table width="728" border="0" align="center" cellpadding="0" cellspacing="0" id="bordes">    
  33.     <tr>
  34.       <td height="27" class="modulo_entrada1"><strong>Codigo:&nbsp;</strong></td><td><select id="codigo"  name="codigo" onChange="myFunction(this.value)">
  35.  
  36. <option value="">Seleccione</option>
  37.  
  38. <?php
  39.  
  40. while($fila=mysql_fetch_array($res)){
  41.  
  42. ?>
  43.  
  44.  <option value="<?php echo $fila['codigo']; ?>"><?php echo $fila['codigo']; ?></option>
  45.  
  46. <?php } ?>
  47.  
  48. </select>
  49. </td>
  50.     <td class="modulo_entrada1"><strong>Medicamento:&nbsp;</strong></td><td><div id="myDiv"></div></td>
  51.     </tr>    
  52.  <tr> <td height="24" colspan="1" class="modulo_entrada1"><strong>Presentación:&nbsp;</strong></td>
  53.    <td><div id="textOculto" style="display: none;">
  54.   <input type="text" id="medicamento" name="medicamento" />
  55. </div> <div id="myDiv2"></div></td>
  56.  <td colspan="1" class="modulo_entrada1"><strong>Cantidad Entregada:&nbsp;</strong></td>
  57.  <td><input name="cantidad_entregada" type="text" class="validate[required]"/></td></tr>
  58.  <tr> <td height="24" colspan="1" class="modulo_entrada1"><strong>Destino:&nbsp;</strong></td>
  59.    <td><input name="destino" type="text" id="destino" size="25" class="validate[required]"/></td>
  60.  <td colspan="1" class="modulo_entrada1"><strong>C.i quien retira:&nbsp;</strong></td>
  61.  <td><input name="ciretira" type="text" class="validate[required,custom[integer]]"/></td></tr>
  62.   <tr> <td height="26" colspan="1" class="modulo_entrada1"><strong>Nombre y Apellido:&nbsp;</strong></td>
  63.    <td><input name="datos_re" type="text" id="destino" size="25" class="validate[required]"/></td>
  64.  <td colspan="1" class="modulo_entrada1"><strong>Telefono:&nbsp;</strong></td>
  65.  <td><input name="telefono" type="text" class="validate[required]"/></td></tr>
  66.  <td colspan="1" class="modulo_entrada1"><strong>Fecha de la entrega:&nbsp;</strong></td>
  67.  <td><input name="fecha_entrega" type="text"  id="datepicker"/></td></tr>
  68.  
  69.  <tr><td height="9"></td></tr>
  70.     </table>

archivo1

Código PHP:
Ver original
  1. <?php
  2. include 'conexion.php';
  3. $r=$_POST['q'];
  4. $con=conexion();
  5. $res=mysql_query("select * from medicina where codigo=".$r."",$con);
  6.  
  7. ?>
  8.  
  9. <select id="medicamento" name="medicamento" onchange="myFunction2(this.value)">
  10.  
  11. <option>Seleccione</option
  12. >
  13. <?php
  14.  while($fila=mysql_fetch_array($res))
  15. {
  16. ?>
  17.  
  18.  <option  value="<?php echo $fila['medicamento'];?>" ><?php echo $fila['medicamento']; ?></option>
  19.  
  20. <?php } ?>
  21.  
  22. </select>

archivo2

Código PHP:
Ver original
  1. <?php
  2. include 'conexion.php';
  3.  
  4. $q=$_POST['r'];
  5. $con=conexion();
  6.  
  7. $res=mysql_query("select * from medicina where codigo=".$q."",$con);
  8.  
  9. ?>
  10.  
  11. <select id="presentacion" name="presentacion">
  12. <option value="-">Seleccione</option>
  13. <?php while($fila=mysql_fetch_array($res)){  ?>
  14.  <option value="<?php echo $fila['presentacion']; ?>"><?php echo $fila['presentacion']; ?></option>
  15. <?php } ?>
  16.  
  17. </select>

El problema radica en archivo uno aqui.
Código PHP:
Ver original
  1. <option  value="<?php echo $fila['codigo'];?>" ><?php echo $fila['medicamento']; ?></option>

en teoria los tres select funcionan bien ya que me trae los datos que quiero de la bd, ahora cuando quiero guardar los datos del formulario el campo medicamento me lo registra con el codigo ya que en el valur tengo esto.
Código PHP:
Ver original
  1. value="<?php echo $fila['codigo'];?>" ><?php echo $fila['medicamento']; ?>
ahora si ese value lo coloco asi.
Código PHP:
Ver original
  1. <option  value="<?php echo $fila['medicamento'];?>" ><?php echo $fila['medicamento']; ?></option>
no me funciona el tercer select ya que esta realacionado con el codigo. ahora como puedo hacer para que me registre el medicamento y no el codigo.