Ver Mensaje Individual
  #12 (permalink)  
Antiguo 16/03/2011, 09:16
Avatar de Patriarka
Patriarka
 
Fecha de Ingreso: enero-2011
Ubicación: Moreno, Buenos Aires, Argentina
Mensajes: 2.851
Antigüedad: 13 años, 3 meses
Puntos: 288
Respuesta: Rellenar campos de texto a partir de un select a la BD

Cita:
Iniciado por avergaf Ver Mensaje
select emp_rut,emp_fono,ciu_nom,emp_mail from empresas
inner join ciudades on
empresas.ciu_cod=ciudades.ciu_cod
where emp_nom='$nombre'


$nombre seria el nombre del text box donde se escribirá el nombre de la empresa a consultar y a partir de este se obtendran los datos...
***************
BUENO ESTO ADAPTALO A TU SISTEMA, PERO DEBERIA FUNCIONAR

Código PHP:
Ver original
  1. $sql='select * from empresas
  2. inner join ciudades on
  3. empresas.ciu_cod=ciudades.ciu_cod';
  4. $res=mysql_query($sql);
  5. if(mysql_num_rows($res) > 0){
  6.   while($row=mysql_fetch_object(res)){
  7.   //VAMOS A EMPEZAR CON UN SOLO CAMPO, LUEGO VAS AGREGANDO LOS DEMAS
  8.   ?>
  9.   <input type="hidden" name="HID_mail_<?php echo $row->emp_nom; ?>" id="HID_mail_<?php echo $row->emp_nom; ?>" value="<?php echo $row->emp_mail; ?>" />
  10.            
  11.   <?php
  12.   }
  13. }
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function valida(){
  3.     var nombre = document.getElementById('nombre').value; //RECUPERO EL VALOR INGRESADO
  4.     alert(nombre);
  5.    
  6.     var mail = document.getElementById('HID_mail_'+nombre).value; //ARMO EL ID DEL HIDDEN QUE TIENE EL MAIL CON EL VALOR INGRSADO
  7.     alert(mail); //muestro el email que CORRESPONDE AL NOMBRE INGRESADO , SI FUNCIONA ESTO SOMOS LOS REYES DEL CARNAVAL
  8.  
  9.     if(mail != null || mail != ''){ //tiene que existir el div para que no de error
  10.         //EN EL CONTENEDOR CREO UN INPUT EDITABLE CON EL MAIL QUE CORRESPONDE AL NOMBRE INGRESADO
  11.         document.getElementById("contenedor").innerHTML = '<input type="text" name="mail" id="mail" value="'+mail+'" />';
  12.     }else{
  13.                 alert('no hay resultados');
  14.         return false;
  15.     }
  16. }
  17. </script>


?>
Código HTML:
Ver original
  1. <input type="text" name="nombre" id="nombre" value="" />
  2. <div id="contenedor" name="contenedor"></div>
  3. <input type="button" name="boton" onclick="return valida();" />

DESPUES ANDA PROBANDO UNO POR UNO LOS CAMPOS QUE QUERES MOSTRAR