Ver Mensaje Individual
  #14 (permalink)  
Antiguo 26/12/2013, 11:36
facugu1998
 
Fecha de Ingreso: diciembre-2013
Mensajes: 21
Antigüedad: 10 años, 4 meses
Puntos: 0
Respuesta: Crear Buscador web y mysql

Hola, yo encontre un buscador en internet que busca en una base de datos y muestra los resultados de forma automática:


Index.php
Código PHP:
Ver original
  1. <head>
  2. <style>
  3. b{color:blue;}
  4. </style>
  5. <style>
  6.  
  7. #myDiv
  8. {
  9. margin-top: 10px;
  10. border-style:dashed;
  11. width: 954px;
  12. height: auto;
  13. text-align: left;
  14. color:#000;
  15. padding:10px 10px;
  16. border-radius:0 0 20px 20px;
  17. }
  18. #myDiv > a {
  19.     color:#000;
  20.    
  21.    
  22. }
  23. #prod-busq{
  24.     margin-top:0px;
  25.     width:100%;
  26.     height:460px;
  27.     display:inline-block;
  28.     }
  29.    
  30. #bus{
  31. background-image:url(input.png);
  32.  padding-left:40px;
  33.  padding-top:10px;
  34.  padding-bottom:10px;
  35.  border:solid 1px #33FF33;
  36. border-radius:5px;
  37.  width:700px;
  38.  height:30px;
  39.  font-size:26px;
  40.  }
  41.  #bus:focus{
  42. box-shadow:0 0 15px #00FF00;
  43. }
  44.  
  45. </style><script type="text/javascript" src="ajax.js"></script>
  46. </head>
  47. <body>
  48. <div style="min-height:700px;">
  49.  
  50. <h1><b style="color:#000; font-family:Allan, cursive; font-size:60px;">Busqueda personalizada:</b></h1>
  51.  
  52. <input type="text" id="bus" name="bus" onkeyup="loadXMLDoc()" required />
  53.  
  54. <div id="myDiv" style="min-height:700px;">
  55. </body>



proc.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. include 'conexion.php';
  4.  
  5. $q=$_POST['q'];
  6. $con=conexion();
  7.  
  8. $sql="select * from productos where clase LIKE '".$q."%' or titulo LIKE '".$q."%'";
  9.  
  10. $res=mysql_query($sql,$con);
  11.  
  12. if(mysql_num_rows($res)==100){
  13.  
  14. echo '<b>No hay sugerencias</b>';
  15.  
  16. }else{
  17.  
  18. echo '<h2 style=" text-decoration:underline;font-family:Allan;">Resultados de la búsqueda</h2><br />';
  19.  
  20. while($fila=mysql_fetch_array($res)){
  21.  
  22. echo'
  23.  
  24. <div id="prod-busq" style="display:inline-block;"> <h3>Nombre:'.$fila['titulo'].'</h3> <h3>Clase:'.$fila['clase'].'</h3>  <p> <b><i><u>Colores disponibles=</u></i></b>   '.$fila['color-1'].', '.$fila['color-2'].', '.$fila['color-3'].', '.$fila['color-4'].' ----- <b><i><u>Tamaño=</u></i></b>   '.$fila['tamano'].'</p> <a href="http://www.forosdelweb.com/f18/Productos/ver.php?Prod='.$fila['prod-id'].'" rel="facebox[.bolder]">Ver el producto</a> <br/><img src="http://www.forosdelweb.com/f18/productos/imagenes/'.$fila['prod-id'].'.jpg" width="130px" height="160px" style="display: inline-block; border: #000 5px double;"/> <hr width="75%"> <hr width="50%"> <hr width="25%">  <hr width="12%"><br /> <br /> <br />
  25.  
  26. ';
  27.  
  28.  
  29. }
  30.  
  31. }
  32.  
  33. ?>


ajax.js

Código Javascript:
Ver original
  1. function loadXMLDoc()
  2. {
  3. var xmlhttp;
  4.  
  5. var n=document.getElementById('bus').value;
  6.  
  7. if(n==''){
  8.  document.getElementById("myDiv").innerHTML="";
  9.  return;
  10. }
  11.  
  12. if (window.XMLHttpRequest)
  13.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  14.   xmlhttp=new XMLHttpRequest();
  15.   }
  16. else
  17.   {// code for IE6, IE5
  18.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  19.   }
  20. xmlhttp.onreadystatechange=function()
  21.   {
  22.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  23.     {
  24.     document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  25.     }else{ document.getElementById("myDiv").innerHTML='<img src="load.gif" width="50" height="50" />'; }
  26.   }
  27. xmlhttp.open("POST","proc.php",true);
  28. xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  29. xmlhttp.send("q="+n);
  30. }



conexion.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. function conexion(){
  4.  
  5. $con = mysql_connect("localhost","root","");
  6.  
  7. if (!$con){
  8.  
  9. die('Could not connect: ' . mysql_error());
  10. }
  11.  
  12. mysql_select_db("productos", $con);
  13.  
  14. return($con);
  15.  
  16. }
  17.  
  18. ?>