Foros del Web » Programando para Internet » PHP »

Jalar datos de mysql a php

Estas en el tema de Jalar datos de mysql a php en el foro de PHP en Foros del Web. Disculpen, lo que pasa es que tengo un combo en php que me jala datos de la bd, pero quiero que al seleccionar un nombre ...
  #1 (permalink)  
Antiguo 02/09/2010, 10:18
 
Fecha de Ingreso: agosto-2010
Mensajes: 147
Antigüedad: 13 años, 8 meses
Puntos: 1
Pregunta Jalar datos de mysql a php

Disculpen, lo que pasa es que tengo un combo en php que me jala datos de la bd, pero quiero que al seleccionar un nombre me jale los datos de esta persona... espero si explicarme... de antemano muchas gracias!!

Asi es como jalo en el combo los datos de la bd en php

Código PHP:
Ver original
  1. <?PHP
  2. // datos de conexión a la BD.
  3. $servidor  ="localhost"; // host
  4. $usuario   ="root";
  5. $clave     ="";
  6.  
  7. $basedatos ="bd_control"; // Indicar una Base de datos.
  8.  
  9. // Conexión a la BD
  10. $conexion = mysql_connect($servidor, $usuario, $clave) or die(mysql_error());
  11. mysql_select_db($basedatos, $conexion) or die(mysql_error());
  12.        
  13. echo "<select size='1' name='atendido' >";// abres el select
  14. echo "<option selected='' value=''> [ Seleccione el Nombre ] </option>";
  15. $sql_query="Select nombre from usuarios";// haces la consulta
  16. $res= mysql_query($sql_query) or die('Error en la consulta'.mysql_error());
  17. while($row = mysql_fetch_array($res,MYSQL_ASSOC)){ //despliegas los resultados
  18. echo "<option value='{$row['nombre']}'>{$row['id_nombre']}  {$row['nombre']}</option>";
  19. }
  20. echo "</select>";//cierras el select  
  21.  
  22. ?>

espero me puedan ayudar, gracias!!!
  #2 (permalink)  
Antiguo 02/09/2010, 10:47
 
Fecha de Ingreso: octubre-2007
Mensajes: 87
Antigüedad: 16 años, 7 meses
Puntos: 1
Respuesta: Jalar datos de mysql a php

se me ocurre...
- puedes hacer un select que al cambiar de datos (seleccionar nombre) envíe esa variable por POST a la misma página y entones seleccionar solo los datos de esa persona...

- podrías hacer que al cambiar los datos de la select ejecutaras un script jquery que cargue los datos que quieras en un div (que contiene la pagina php con los datos de ese operario en concreto...)

- algo mas "feo de código" meter todos los datos de las personas en arrays javascript y al cambiar de datos la select cargue el array concreto donde tu quieras...

yo personalmente usaría jquery en este caso, ya que te permite cargar una pagina en un div...

medita sobre ello ;)
  #3 (permalink)  
Antiguo 02/09/2010, 10:52
 
Fecha de Ingreso: agosto-2010
Mensajes: 147
Antigüedad: 13 años, 8 meses
Puntos: 1
Respuesta: Jalar datos de mysql a php

la vdd no soy experta en esto de php... y no se hacerlo o como hacerlo...
  #4 (permalink)  
Antiguo 02/09/2010, 10:54
 
Fecha de Ingreso: febrero-2010
Mensajes: 818
Antigüedad: 14 años, 2 meses
Puntos: 55
Respuesta: Jalar datos de mysql a php

aca te dejo alguna idea de como hacerlo con jquery (basico) espero se entienda

Código PHP:

<script>
//esto significa que cuando el select con id=cliente cambie por post va enviar el valor a carga_select2.php con el nombre de variable resp_com_emp
//y los valores que traiga de vuelta los va a poner en el select con id=resp_cliente_tecnico que se declaro vacio en un principio
$(document).ready(function(){
    $("#cliente").change(function(){
        $.post("carga_select2.php",{ resp_com_emp:$(this).val() },function(data){$("#resp_cliente_tecnico").html(data);})
    });
})
</script>

<?
echo'<tr><td style="text-align:right;">Cliente: *</td><td><select name="cliente" id="cliente"><option value="NULL">Seleccione al Cliente</option>';


//aca llene los datos del primer select da lo mismo si es estatico o dinamico
    
$SQL_Clientes "SELECT name,debtorno FROM debtorsmaster";
        
$RES_Clientes DB_query($SQL_Clientes,$db);
       
        while(
$rows DB_fetch_assoc($RES_Clientes,$db)){
            echo 
'<option value="'$rows['debtorno'] .'">'$rows['name'] .'</option>';
        }
       
        echo 
'</select></td></tr>';


   
           
               
        echo
'<tr><td style="text-align:right;">Responsable Tecnico: *</td><td><select name="resp_cliente_tecnico" id="resp_cliente_tecnico"><option value="NULL">Seleccione</option></select>
                                                                        </td></tr>'
;
       
?>

//Lo que deberia ir en el archivo carga_select2.php
<?
//en caso de recibir la variable que le enviaste por jquery
if(isset($_REQUEST['resp_com_emp']) AND $_REQUEST['resp_com_emp']!=''){
    
$Area$_REQUEST['resp_com_emp'];

    
//se hace una consulta con ese criterio de busqueda
    
$sql "SELECT contactname FROM custcontacts WHERE debtorno='"$Area ."' ORDER by contactname";
    
$res DB_query($sql,$db);

    
//se insertan los option en el select declarado en la otra pagina
    
while($row_ DB_fetch_assoc($res)){
        echo 
'<option value="'$row_['contactname'] .'">'$row_['contactname'] .'</option>';
    }
   
}
?>
  #5 (permalink)  
Antiguo 06/09/2012, 12:49
 
Fecha de Ingreso: mayo-2009
Ubicación: Loja - Ecuador
Mensajes: 2
Antigüedad: 15 años
Puntos: 0
Respuesta: Jalar datos de mysql a php

Ayuda tengo este código que en mi compu está funcionando perfectamente

pero al llevarlo a otra maquina y ejecutarlo me presenta estas dos líneas de código o errores

Notice: C:\xampp\htdocs\ministerio\consulta.php line 62 - Undefined index: miCombo

Notificación: C:\xampp\htdocs\ministerio\consulta.php línea 122- Undefined index: imprimir

Código PHP:
Ver original
  1. <html >
  2.     <head>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.     <title>Pago a Contratados</title>
  5.     </head>
  6.  
  7.     <body>
  8.  
  9.   <table width="927" border="0">
  10.     <tr>
  11.       <th width="813" height="99" scope="row"><p><strong>REPUBLICA DEL ECUADOR</strong></p>
  12.         <p><strong>DIRECCIÓN PROVINCIAL DE EDUCACIÓN HISPANA DE ZAMORA</strong></p>
  13.         <p><strong>PAGO DE HABERES</strong></p></th>
  14.     </tr>
  15.   </table>
  16.   <p>&nbsp;</p>
  17.  
  18.     <p><strong>
  19.     <!-- #BeginDate format:Am1 -->Septiembre 5, 2012<!-- #EndDate --></strong></p>
  20.     <p><strong></strong></p>
  21. <FORM method=post action="consulta.php" >
  22.   <tr>
  23.     <td colspan="2"><p>
  24.       <label>Contratado:
  25.         <!--Label-->
  26.         </select>
  27.       </label>
  28.       <?php
  29.  
  30.     include('Conectarse/conectar.php');
  31.     $link = Conectarse( );
  32.     $query2=mysql_query("Select * from tabla1");
  33.  
  34.    
  35.  
  36.     if ($row = mysql_fetch_array($query2)){
  37.     echo '<select name= "miCombo">';
  38.     echo'<option value="--Seleccione">---Seleccione una persona---';
  39.     do {
  40.     echo '<option value= "'.$row["id"].'">'.$row["apellidosnombres"].'</option>';
  41.     } while ($row = mysql_fetch_array($query2));
  42.     echo '</select>';
  43.        
  44.        
  45.     }
  46.  
  47.     ?>
  48.       <input type="submit" name="ver" value="Ver Detalles" />
  49.     </p>
  50.       <table width="674" border="0">
  51.         <tr>
  52.           <th width="500" scope="col"><p>NOMINA DE CONTRATO </p></th>
  53.           <th width="10" scope="col">&nbsp;</th>
  54.           <th width="150" scope="col"><p>INSTITUCIONAL</p></th>
  55.         </tr>
  56.     </table></td>
  57. </tr>
  58.  
  59.     <table width="937" height="261">
  60.     <?php
  61.     $id ='$_POST[miCombo]';
  62.     $query3=mysql_query("Select * from tabla1 where id='$_POST[miCombo]'");
  63.     while ($fila=mysql_fetch_array($query3))
  64.     {
  65.     ?>
  66.     <tr bgcolor="#999999">
  67.     <td width="269" height="73" align="right"><strong>Nombres :</strong></td>
  68.     <td width="261"><input type="text" size="42" value="<?php echo $fila['apellidosnombres']?>" maxlength="42" name="nombre" readonly="yes" /></td>
  69.     <td width="244" align="right"><strong>Cédula :</strong></td>
  70.     <td width="143"><input type="text" size="15" value="<?php echo $fila['cedula']?>" maxlength="15" name="cp5" readonly="yes" /></td>
  71.     </tr>
  72.     <tr align="left" valign="middle" bgcolor="#FFFFFF">
  73.     <td align="right"><p><strong><em>Rubro Ingresos</em></strong></p></td>
  74.     <td align="center"><strong><em>Monto</em></strong></td>
  75.     <td align="center"><strong><em>Rubro Descuentos</em></strong></td>
  76.     <td align="center"><strong><em>Monto</em></strong></td>
  77.     </tr>
  78.     <tr bgcolor="#CCCCCC">
  79.     <td align="right"><p><strong>REMUNERACIONES UNIFICADAS</strong></p>
  80.       <p><strong> 2012 :</strong></p></td>
  81.     <td><input type="text" size="10" value="<?php echo $fila['sueldo']?>" maxlength="10" name="apellido2" readonly="yes" /></td>
  82.     <td align="right"><strong>APORTE PERSONAL IESS :</strong></td>
  83.     <td><input type="text" size="10" value="<?php echo $fila['aportepersonaliess']?>" maxlength="10" name="cp4" readonly="yes" /></td>
  84.     </tr>
  85.     <tr bgcolor="#CCCCCC">
  86.     <td align="right"><strong>FONDO DE RESERVA 2012 :</strong></td>
  87.     <td><input type="text" size="10" value="<?php echo $fila['fondoreserva']?>" maxlength="10" name="cp2" readonly="yes" /></td>
  88.     <td align="right"><strong>COOP. MEGO :</strong></td>
  89.     <td><input type="text" size="10" value="<?php echo $fila['coopmego']?>" maxlength="10" name="cp3" readonly="yes" /></td>
  90.     </tr>
  91.     <tr bgcolor="#CCCCCC">
  92.       <td height="34" align="right"><strong>TOTAL :</strong></td>
  93.       <td><input type="text" size="10" value="<?php echo $fila['total']?>"maxlength="10" name="cp" readonly="yes" /></td>
  94.       <td align="right"><strong>PRESTAMO QUIROGRAFARIO :</strong></td>
  95.       <td><input type="text" size="10" value="<?php echo $fila['prestamoquirografario']?>" maxlength="25" name="cp" readonly="yes" /></td>
  96.       </tr>
  97.     <tr bgcolor="#CCCCCC">
  98.       <td height="34" align="right">
  99.        
  100.           <p><strong> A COBRAR :</strong></p>
  101.        
  102.       </td>
  103.       <td><input type="text" size="10" value="<?php echo $fila['acobrar']?>" maxlength="10" name="cp" readonly="yes" /></td>
  104.     <td height="34" align="right"><strong>TOTAL :</strong></td>
  105.     <td><input type="text" size="10" value="<?php echo $fila['total2']?>" maxlength="10" name="cp" readonly="yes" /></td>
  106.    
  107.    
  108.      
  109.  
  110.     </tr>
  111.         <td width="269" align="right"><input type="hidden" size="10" value="<?php echo $fila['id']?>" maxlength="10" id="id" name="id" readonly="yes" /></td>
  112.     </table>
  113.  
  114.     <?
  115.     }
  116.    
  117.    
  118.      echo "<input type='submit' id='i' name='imprimir' value='Imprimir' />";
  119.      
  120.     ?>
  121.     <?
  122.      if ($_POST["imprimir"])
  123.     {
  124.         $id= $_POST['id'];
  125.         echo "<body onload=\"ventanaRecomendaciones('/ministerio/pdfs/i_usuarios2.php?id=".$id."')\"></body>";
  126.     }
  127.     ?>
  128. <script>
  129. function ventanaRecomendaciones (URL)
  130. {
  131.  
  132.   window.open(URL,"ventana1","width=523, height=527, scrollbars=no, menubar=no, location=no, resizable=no, toolbar=no, directories=no, top=100,left=100")
  133. }
  134. </script>      
  135.   </td>
  136.     </tr>
  137.  
  138.   </form>
  139.     <p>&nbsp;</p>
  140.     </body>
  141.    
  142.     </html>

Última edición por hfmp29; 06/09/2012 a las 13:02

Etiquetas: mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:42.