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

y es re facil:
cuando ingresas el NOMBRE en el campo de texto y haces click en un BUTTON
con alguna funcion JS le envias el valor ingresado y SIN ENVIAR el formulario
validas si hay coincidencias en la base para RELLENAR los otros campos.

cualquiera diria que tenes que ir a otra pagina y traer los datos, es valido, pero no hace falta.

como lo haces? simple:

1- guarda todos los registros en campos HIDDEN asignandole algun ID que diferencie a cada grupo de registros.

2-si le voy a enviar el NOMBRE ingresado desde la funcion js entonces ese va a ser el ID de cada grupo de gistros que quiero mostrar

3- aca te dejo la funcion
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function changeImage(nombre){
  3.     var idImage=document.getElementById('HID_'+nombre).value;  //NOMBRE INGRESADO!!!!
  4.     alert(idImage);  // LO MUESTRO PARA VER SI EXISTE
  5.        //CARGO EN OTRAS VARIABLES EL RESTO DE LOS DATOS SEGUN EL NOMBRE INGRESADO
  6.      
  7.     var hidPath=document.getElementById('HID_img_staff_'+idImage).value;
  8.     var hidCargo=document.getElementById('HID_cargo_staff_'+idImage).value;
  9.     var hidSchool=document.getElementById('HID_school_staff_'+idImage).value;
  10.     var hidNombre=document.getElementById('HID_nombre_staff_'+idImage).value;
  11.     var hidCV=document.getElementById('HID_cv_staff_'+idImage).value;
  12.     //SIEMPRE QUE HALLA RESULTADOS
  13.         //ACTUALIZO LA INFORMACION
  14.        //ACA YO PUSE TODO EN UNA CAPA PERO VOS TENES ADAPTARLO A TU SISTEMA
  15.     if(hidPath!=null || hidPath!=''){
  16.         document.getElementById("staff_info").innerHTML='<table><tr><td rowspan="5"><img height="80px" width="80px" src="'+hidPath+'" /></td></tr><tr><td>&nbsp;</td></tr><tr><td><strong>'+hidNombre+'</strong></td></tr><tr><td>'+hidCargo+'</td></tr><tr><td>'+hidSchool+'</td></tr></table>';
  17.         document.getElementById("staff_info").innerHTML += '<div style="" id="txt_staff">'+hidCV+'<div>';
  18.     }else{
  19.         return false;
  20.     }
  21. }
  22. </script>
IMPORTANTE: TENE EN CUENTA EL NOMBRE DE LOS HIDDEN.

LA QUERY ES FACIL
$sql='select * from staff';
$res=mysql_query($sql);
while($row=mysql_fetch_object($res)){
<input type="hidden" name="HID_img_staff_<?php echo $row->nombre; ?>" id="HID_img_staff_<?php echo $row->nombre; ?>" value="<?php echo $imagen; ?>" />
<input type="hidden" name="HID_cargo_staff_<?php echo $row->nombre; ?>" id="HID_cargo_staff_<?php echo $row->nombre; ?>" value="<?php echo $aStaff->getCargo()->getName(); ?>" />
<input type="hidden" name="HID_school_staff_<?php echo $row->nombre; ?>" id="HID_school_staff_<?php echo $row->nombre; ?>" value="<?php echo $aStaff->getSchool()->getName() ?>" />
<input type="hidden" name="HID_nombre_staff_<?php echo $i; ?>" id="HID_nombre_staff_<?php echo $row->nombre; ?>" value="<?php echo $aStaff->getlastName().', '.$aStaff->getName(); ?>" />
<input type="hidden" name="HID_cv_staff_<?php echo $row->nombre; ?>" id="HID_cv_staff_<?php echo $row->nombre; ?>" value="<?php echo $aStaff->getCvDescription(); ?>" />

}


LA IDEA ES QUE OCULTES LA INFORMACION Y SEGUN LO QUE INGRESES EN EL TEXTBOX RECUPERES LA INFO TANTO DESEADA