Jump to content


Photo

[SOLUCIONADO] como crear un buscador con php-mysql PDO con POO?


  • Please log in to reply
2 replies to this topic

#1 novato

novato

    Member

  • Miembros
  • PipPip
  • 35 posts

Posted 12 February 2014 - 06:38 PM

OK, SALUDOS TALVEZ ME AYUDAN CON ESTO YA QUE ESTOY ENCOCADO , CERRADO .

LO QUE QIERO HACER ES UN BUSCADOR DE UNA TABLA ESPECIFICA DE MI BD EN MYSQL ES POR METODO POST
LES VOY A DEJAR LOS ARCHIVOS CON EL CODIGO PARA QUE MIREN ASTA DONDE VOY UNICAMENTE QIERO BUSCAR UN USARIO DE LA TABLA USUARIO CON SU ID Y Q MAS ABAJO SE MUESTRE EL RESULTADO DE LA BUSQUEDA

INDEX.PHP


delphi
  1. <?php
  2. require_once("class/class.php");
  3. $tra=new Trabajo();
  4. if(isset($_POST["busco"]) and $_POST["busco"]=="si")
  5. {
  6.   $trab->get_usuario_por_id();
  7.     exit;
  8. }
  9. ?>
  10. <!doctype html>
  11. <html lang="es">
  12. <head>
  13. <meta charset="UTF-8">
  14. <title>Document</title>
  15. </head>
  16. <body>
  17.  
  18. <form action="" name="form" method="POST">
  19. <input type="text" class="nombfind" name="id"/>
  20. <input type="hidden" name="busco" value="si">
  21.   <input type="submit" class="boton" value="Buscar" title="Buscar" />
  22. </form>
  23.  
  24. </body>
  25. </html>



CLASS.PHP


delphi
  1. <?php
  2.  
  3. class Trabajo
  4. {
  5.     private $dbh;
  6.     private $busc_x_id_usuario;
  7.    
  8.     public function __construct()
  9.     {
  10.         $this->dbh=new PDO('mysql:host=localhost;dbname=BDGENTE', "root", "");
  11.         $this->findcliente=array();
  12.         $this->pro=array();
  13.     }
  14.  
  15.     private function set_names()
  16.     {
  17.         return $this->dbh->query("SET NAMES 'utf8'");   
  18.     }
  19.    
  20.     public function get_usuario_por_id()
  21.         {   
  22.             self::set_names();
  23.             $sql="select id_usuario from usuario where id_usuario=? ";
  24.             //echo $sql;
  25.             print_r($_POST);
  26.             $stmt=$this->dbh->prepare($sql);
  27.             if($stmt->execute( array($busca) ) )
  28.             {
  29.                 while($row = $stmt->fetch())
  30.                 {
  31.                     $this->busc_x_id_usuario[]=$row;
  32.                 }
  33.                 return $this->busc_x_id_usuario;
  34.                 $this->dbh=null;
  35.             }
  36.        
  37.     }
  38.  
  39.  
  40. }
  41.  
  42.  
  43. ?>




aqui les dejo el link para descargar la base de datos
https://www.mediafir...v81iq5ypddsdvil
  • 0

#2 novato

novato

    Member

  • Miembros
  • PipPip
  • 35 posts

Posted 12 February 2014 - 07:17 PM

ya no es necesario yo mismo me conteste ace 2años atras  aqui les dejo el link

en la clase acomo la tengo aorita asi la dejo solo agos los cambio enel index de ace 2 años

http://www.delphiacc...68084/#msg68084
  • 0

#3 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4945 posts
  • LocationMéxico

Posted 13 February 2014 - 08:31 AM

Muy bien compañero.
  • 0




IP.Board spam blocked by CleanTalk.