martes, 28 de septiembre de 2010

Codigo php para busqueda y listado nombres o letras asociada

<?php

if(isset($buscar) && $buscar=="")
{
echo"Debe especificar una cadena a buscar";
exit;
}


   $link = mysql_connect("fdb2.runhosting.com","499386_prueba","0178b9fb");
   mysql_select_db("499386_prueba",$link);
   $result = mysql_query("SELECT * FROM cliente WHERE nombre LIKE '%$buscar%' ORDER BY nombre;",$link);
  
    echo $_POST[buscar];
 
if ($row = mysql_fetch_array($result))
{
    echo "<table border ='1'> \n";
    //Mostramos los nombres de las tablas
    echo "<tr> \n";
    while ($field = mysql_fetch_field($result))
    {
        echo "<td>$field->name</td> \n";
    }
    echo "</tr> \n";
    do
    {
      echo "<tr> \n";
      echo "<td>".$row["cedula"]."</td> \n";
      echo "<td>".$row["nombre"]."</td> \n";
      echo "<td>".$row["apellido"]."</td> \n";
      echo "<td>".$row["direccion"]."</td> \n";
      echo "<td>".$row["telefono"]."</td> \n";
      echo "<td><a href='mailto:".$row["email"]."'>".$row["email"]."</a></td> \n";
      echo "</tr> \n";
    }while($row = mysql_fetch_array($result));
    echo "</table> \n";
}
else
{
echo "¡ No se ha encontrado ningún registro !";

}
?>

No hay comentarios:

Publicar un comentario