Con este motor de busqueda podran hacerla por Id o por nombre del usuario, vamos a crear 2 archivos el prmiero es clas.php donde tendremos la conexion a la base de datos la consulta de la busqueda, el segundo archivo es el index.html donde tendremos un formulario con un campo input tipo texto y boton.
Solamente creen la base de datos y la tabla con sus campos.
class.php
<?php
require_once("clas.php");
?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/stilo.css" rel="stylesheet" type="text/css" />
<title>Documento sin título</title>
</head>
<body>
<form name="form2" method="post" action="">
<strong>Busqueda x Nick:</strong>
<input type="text" name="T1" size="20">
<input type="hidden" name="grabar" value="si">
<input type="submit" value="buscar" name="buscar">
</form>
<?php
if (isset($_POST["grabar"]) and $_POST["grabar"]=="si")
{
$tra=new Trabajo();
?> <div class="menu_navfind" >
<?php
$buscar_contactos=$tra->get_findcontactos($_POST["T1"]);
for ($x=0;$x<sizeof($buscar_contactos);$x )
{
?> <form name="find" id="find" action="" method="post" enctype="multipart/form-data">
<fieldset class="buscar">
<legend class="legen2"><span class="spand">Registro encontrado</span></legend>
<img class="fotouser" src="impic/FotosUsuarios/<?php echo $buscar_contactos[$x]["foto"];?>"
width="143" height="179" border="1" /></img>
<label class="nick">Nick:</label>
<input type="text" name="inputext" disabled="disabled" value="<?php echo $buscar_contactos[$x]["nick"];?>"></input><br><br>
<label class="etiqtas">Nombre:</label>
<input type="text" name="inputext" disabled="disabled" size="58" value="<?php echo $buscar_contactos[$x]["nombre"];?> "></input><br><br>
<label class="email">Email:</label>
<input type="text" name="inputext" disabled="disabled" size="33" value="<?php echo $buscar_contactos[$x]["email"];?> "></input><br><br>
<label class="telf">Tefl:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["telf"];?> "></input>
<label class="cel1">Cel1:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["cel1"];?> " />
</input>
<label class="cel2">Cel2:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["cel2"];?> "></input><br><br>
<label class="dir">Dir:</label>
<textarea cols="100" rows="5" id="dir" name="inputext2" disabled="disabled" > <?php echo $buscar_contactos[$x]["dir"];?></textarea>
</fieldset>
</form>
<?php
?>
</div>
</body>
</html>
Solamente creen la base de datos y la tabla con sus campos.
class.php
class Trabajo { private $showcontactos=array(); private $findcontactos=array(); public function __construct() { $this->showcontactos=array(); $this->findcontactos=array(); } public static function con() { $con=mysql_connect("localhost","root",""); mysql_query("SET NAMES 'utf8'"); mysql_select_db("bdprueba"); return $con; } /*** BUSCAR CONTACTOS X NICK ***/ public function get_findcontactos($find) { $sql="select * from tbagenda where nick LIKE '%".$find."%' or nombre LIKE '%".$find."%' "; $res=mysql_query($sql,Conectar::con()); while ($reg=mysql_fetch_assoc($res)) { $this->findcontactos[]=$reg; } return $this->findcontactos; } }index.html
<?php
require_once("clas.php");
?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/stilo.css" rel="stylesheet" type="text/css" />
<title>Documento sin título</title>
</head>
<body>
<form name="form2" method="post" action="">
<strong>Busqueda x Nick:</strong>
<input type="text" name="T1" size="20">
<input type="hidden" name="grabar" value="si">
<input type="submit" value="buscar" name="buscar">
</form>
<?php
if (isset($_POST["grabar"]) and $_POST["grabar"]=="si")
{
$tra=new Trabajo();
?> <div class="menu_navfind" >
<?php
$buscar_contactos=$tra->get_findcontactos($_POST["T1"]);
for ($x=0;$x<sizeof($buscar_contactos);$x )
{
?> <form name="find" id="find" action="" method="post" enctype="multipart/form-data">
<fieldset class="buscar">
<legend class="legen2"><span class="spand">Registro encontrado</span></legend>
<img class="fotouser" src="impic/FotosUsuarios/<?php echo $buscar_contactos[$x]["foto"];?>"
width="143" height="179" border="1" /></img>
<label class="nick">Nick:</label>
<input type="text" name="inputext" disabled="disabled" value="<?php echo $buscar_contactos[$x]["nick"];?>"></input><br><br>
<label class="etiqtas">Nombre:</label>
<input type="text" name="inputext" disabled="disabled" size="58" value="<?php echo $buscar_contactos[$x]["nombre"];?> "></input><br><br>
<label class="email">Email:</label>
<input type="text" name="inputext" disabled="disabled" size="33" value="<?php echo $buscar_contactos[$x]["email"];?> "></input><br><br>
<label class="telf">Tefl:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["telf"];?> "></input>
<label class="cel1">Cel1:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["cel1"];?> " />
</input>
<label class="cel2">Cel2:</label>
<input type="text" name="inputext" disabled="disabled" size="8" value="<?php echo $buscar_contactos[$x]["cel2"];?> "></input><br><br>
<label class="dir">Dir:</label>
<textarea cols="100" rows="5" id="dir" name="inputext2" disabled="disabled" > <?php echo $buscar_contactos[$x]["dir"];?></textarea>
</fieldset>
</form>
<?php
exit();
} }
?>
</div>
</body>
</html>
No hay comentarios :
Publicar un comentario