Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/08/2014, 14:35
Avatar de MaNuX0218
MaNuX0218
 
Fecha de Ingreso: marzo-2014
Mensajes: 787
Antigüedad: 10 años, 1 mes
Puntos: 67
Respuesta: Busqueda ajax

Haber mostrare todos, html, php(mysql) y ajax

Código HTML:
Ver original
  1. <form action="" method="get">
  2.  
  3. <input type="text" name="nom" id="valor1" maxlength="13">
  4.  
  5. <input type="text" name="ape" id="valor2" maxlength="6">
  6.  
  7. </form>

Código PHP:
Ver original
  1. <?php
  2.  
  3. $con = mysql_connect('localhost','root', '');
  4. mysql_select_db('db', $con);
  5.  
  6. $nom = mysql_real_escape_string(strip_tags($_GET['nom']));
  7. $ape = mysql_real_escape_string(strip_tags($_GET['ape']));
  8.  
  9. $sql = mysql_query('SELECT * FROM tabla WHERE nombre LIKE "'.$_GET['nom'].'%" AND apellido LIKE "'.$_GET['ape'].'%"', $con);
  10.  
  11. while($row=mysql_fetch_array($sql)){
  12.  
  13. echo '<tbody>
  14. <td>'.$row['nombre'].'</td>
  15. <td>'.$row['apellido'].'</td>
  16. <td>'.$row['edad'].'</td>
  17. <td>'.$row['sexo'].'</td>
  18. </tbody>';  
  19.  
  20. }
  21.  
  22. ?>

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2. $("#valor1, #valor2").keyup(function(){
  3.  
  4. var
  5. dato1 = $("#valor1").val(),
  6. dato2 = $("#valor2").val();
  7.      
  8. $.ajax({
  9. type: "GET",
  10. url: "pages/result.php",
  11. dataType: "html",
  12. beforeSend: function(){
  13. $("#resultado").html("<img src='public/images/ajax-loader.gif' width='20' height='20' />");
  14. },
  15. success: function(data){                                                  
  16. $("#resultado").html(data);
  17. $("#resultado").val(consulta);
  18. }
  19. });                                                                                
  20. });                                                                
  21. });