Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/04/2015, 13:25
juasbhu
 
Fecha de Ingreso: abril-2015
Mensajes: 6
Antigüedad: 9 años
Puntos: 0
Respuesta: seleccionar y enviar a input? buscador

Si que pena, pido disculpas es la primera ves aqui.

buscador.php

Código PHP:
Ver original
  1. include("../controlador/config.php");
  2. include("../controlador/connection.php");
  3.  
  4. $ln = new connection($hostbd,$userbd,$passbd,$bd,$port);
  5.  
  6. sleep(1);
  7.  
  8. $search = '';
  9.  
  10. if (isset($_POST['search'])){
  11. $search = strtolower($_POST['search']);
  12. }
  13. $Consulta=$ln->query("SELECT cli.id_cliente, cli.nom_cliente, mas.id_mascota, mas.nom_mascota FROM cliente cli LEFT JOIN mascota mas ON cli.id_cliente=mas.id_cliente
  14. WHERE cli.id_cliente LIKE '%".$ln->safe($search)."%' OR cli.nom_cliente LIKE '%".$ln->safe($search)."%' ORDER BY cli.nom_cliente DESC LIMIT 5;");
  15.  
  16. $fila = mysql_fetch_assoc($Consulta);
  17. $total = mysql_num_rows($Consulta);
  18. ?>
  19. <?php if($total>0 && $search!=''){ ?>
  20. <h2>Resultados de la busqueda</h2>
  21. <?php do{ ?>
  22. <script>
  23. function myFunction() {
  24. var a = document.getElementById("id_cli").innerHTML ;
  25. document.getElementById("id_cliente").value = a;
  26. var b = document.getElementById("id_mas").value ;
  27. document.getElementById("id_mascota").value = b;
  28. }
  29. </script>
  30. <div class="art">
  31. <input type="hidden" id="id_mas" value="<?php echo $fila['id_mascota']; ?>" >
  32. Doc Num: <span id="id_cli" class="titulo" ><?php echo utf8_encode($fila['id_cliente']) ?></span></br>
  33. Nombre: <span class="contenido"><?php echo str_replace($search, '<strong>'.$search.'</strong>', substr(utf8_encode($fila['nom_cliente']),0,15)) ?></span></br>
  34. Mascota: <span class="contenido"><?php echo str_replace($search, '<strong>'.$search.'</strong>', substr(utf8_encode($fila['nom_mascota']),0,15)) ?></span>
  35. <button onclick="myFunction()" > Seleccion</button>
  36.  
  37. </div>
  38. <?php }while ($fila=mysql_fetch_assoc($Consulta)); ?>
  39. <?php }
  40. elseif($total>0 && $search=='') echo '<h2>Ingresa un páramtro de búsqueda</h2><p>Ingresa palabras claves relacionadas entre si</p>';
  41. else echo '<h2>No se han encontrado resultados</h2><p>Sin Registrar</p>';


aqui el form
Código HTML:
Ver original
  1. <div class="form center">
  2. <form action="" method="POST" name="search_form" id="search_form">
  3. <input type="text" name="search" id="search"
  4. </form>
  5. </div>
  6. <div id="resultados"></div>
  7. </div>


aqui el ajax

Código Javascript:
Ver original
  1. $(function(){
  2. $('#search').focus();
  3. $('#search_form').submit(function(e){
  4. e.preventDefault();
  5. })
  6. $('#search').keyup(function(){
  7. var envio = $('#search').val();
  8. $('#logo').html('<h2>El buscador de soy sebas.com</h2> <hr/>'); /*Cambio el logo por el texto con el id*/
  9. $('#resultados').html('<h2><img src="img/loading.gif" width="16"/> Cargando </h2>');/*aqi tengo la imgane de cargando*/
  10.  
  11. $.ajax({
  12. type: 'POST',
  13. url: 'php/buscador.php',
  14. data: ('search='+envio),
  15. success: function(resp){
  16. if(resp!=""){
  17. $('#resultados').html(resp)
  18. }
  19. }
  20. })
  21. })
  22.  
  23. })