Foros del Web » Programando para Internet » PHP »

buscador php para mysql

Estas en el tema de buscador php para mysql en el foro de PHP en Foros del Web. holas chicos a ver quien me puede brindar su apoyo, estoy tratando de hacer un buscador en php para una base de datos mysql pero ...
  #1 (permalink)  
Antiguo 04/04/2012, 15:52
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
buscador php para mysql

holas chicos a ver quien me puede brindar su apoyo, estoy tratando de hacer un buscador en php para una base de datos mysql pero no me sale, y ando a medio camino.

la idea es la siguiente prioridad:

1.Sitio web(dato proviene de un combo-box extricto)
2.Titulo(textbox)
3.Rango de fechas ( todo lo realizado entre $Dia1 hasta el $Dia2)

seria los tres argumento a destacar, indico solo es necesario que UNO (1) de los 3 campos este lleno para realizar la búsqueda y que.

Codigo hasta el momento:

Código PHP:
Ver original
  1. <?php
  2.     header('content-type: text/html; charset=utf-8');
  3.     // Si entramos es que todo se ha realizado correctamente
  4.     include("config/config.php");
  5.    
  6.     $link = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  7.     mysql_select_db($dbname,$link) or die('No se puede seleccionar la base de datos<br>');
  8.    
  9.     $reporte=mysql_query("select * FROM art WHERE DATE_FORMAT(fecha) BETWEEN '$ini' AND '$fin' ");
  10.    
  11.  
  12.     SELECT * FROM art WHERE title MATCH(title) AGAINST ($title) if (SELECT * FROM art WHERE website LIKE '%website') order by art_pk DESC;
  13.  
  14.  
  15. ?>
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #2 (permalink)  
Antiguo 04/04/2012, 16:17
 
Fecha de Ingreso: marzo-2012
Mensajes: 13
Antigüedad: 12 años
Puntos: 1
Respuesta: buscador php para mysql

yo acabo de hacer un buscador, eres nuevo? ya tienes el formulario de envio o solo muestras los datos?
  #3 (permalink)  
Antiguo 04/04/2012, 16:26
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: buscador php para mysql

Actualiso los querry usados para la consulta, aun faltaria unirlas en una sola consulta:

Código PHP:
Ver original
  1. <?php
  2.     header('content-type: text/html; charset=utf-8');
  3.     // Si entramos es que todo se ha realizado correctamente
  4.     include("config/config.php");
  5.     $link = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  6.     mysql_select_db($dbname,$link) or die('No se puede seleccionar la base de datos<br>');
  7.     $title=$_POST['title'];
  8.     $website=$_POST['wscb'];
  9.     $fecsea1=$_POST['fecsea1'];
  10.     $fecsea2=$_POST['fecsea2'];
  11.    
  12.     //busqueda por website:
  13.     $result1 = mysql_query("SELECT * FROM art WHERE website LIKE '$website' ORDER BY art_pk DESC", $link);
  14.     //busqueda por titulo:
  15.     $result2 = mysql_query("SELECT * FROM art WHERE title MATCH(title) AGAINST ($title) ORDER BY art_pk DESC", $link);
  16.     //busqueda por fecha(formato de la fecha en la base de datos es timestamp:
  17.     $result3 = mysql_query("select * FROM art WHERE DATE_FORMAT(fecha) BETWEEN '$fecsea1' AND '$fecsea2' ORDER BY art_pk DESC", $link);
  18.    
  19.  
  20. ?>

el formulario ya lo tengo

es asi:

Código HTML:
Ver original
  1. <form name="form1" method="post" id="form1" action="liste.php">
  2.                             <table width="653" border="0" cellspacing="0" cellpadding="0">
  3.                                 <tr>
  4.                                     <td width="77">Fecha Inicio</td>
  5.                                     <td width="184"><input name="fecsea1" type="text" id="fecsea1" style="width:120px" readonly>
  6.                                     <a href="javascript:NewCal('fecsea1','YYYYDDMM',true,24)">
  7.                                             <img src="date time picker/cal.gif" width="16" height="16" border="0" alt="selecion de fecha"/>
  8.                                             </a>
  9.                                     </td>
  10.                                     <td width="63">Titulo</td>
  11.                                     <td colspan="2"><input name="title" type="text" id="title" style="width:98%" value="" /></td>
  12.                                 </tr>
  13.                                 <tr>
  14.                                     <td>Fecha Final</td>
  15.                                     <td><input name="fecsea2" type="text" id="fecsea2" style="width:120px" readonly>
  16.                                     <a href="javascript:NewCal('fecsea2','YYYYDDMM',true,24)">
  17.                                             <img src="date time picker/cal.gif" width="16" height="16" border="0" alt="selecion de fecha"/>
  18.                                             </a>
  19.                                     </td>
  20.                                     <td>Website</td>
  21.                                     <td width="239"><?php
  22.                                                 $consulta = mysql_query("SELECT site FROM website ORDER BY site", $link);
  23.                                                 //Llenas el combo
  24.                                                 if ($row = mysql_fetch_array($consulta)){
  25.                                                     echo '<select id="wscb" style="width:80%" name= "wscb">';
  26.                                                     do {
  27.                                                         echo '<option value= "'.$row["site"].'">'.$row["site"].'</option>';
  28.                                                     } while ($row = mysql_fetch_array($consulta));
  29.                                                         echo '</select>';
  30.                                                 }
  31.                                             ?></td>
  32.                                     <td width="90"><input align="center" name="Buscar" type="submit" value="Buscar"></td>
  33.                                 </tr>
  34.                             </table>
  35.                         </form>


ME hace falta:

comprobante que al menos un dato este lleno,
fusión de las 3 consultas en una sola en el orden mostrado y que al imprimirlo lo haga en el orden de las llave única. la impresión de esto en pantalla es otro argumento que aun estoy compensando a hacer mañana lo actualizo
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #4 (permalink)  
Antiguo 05/04/2012, 11:35
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: buscador php para mysql

Simplificacion del querry:

Código PHP:
Ver original
  1. <?php
  2.     header('content-type: text/html; charset=utf-8');
  3.     // Si entramos es que todo se ha realizado correctamente
  4.     include("config/config.php");
  5.     $link = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  6.     mysql_select_db($dbname,$link) or die('No se puede seleccionar la base de datos<br>');
  7.     $title=$_POST['title'];
  8.     $website=$_POST['wscb'];
  9.     $fecsea1=$_POST['fecsea1'];
  10.     $fecsea2=$_POST['fecsea2'];
  11.    
  12.     //busqueda por website-> luego titulo-> luego fecha:
  13.     $result1 = mysql_query("SELECT * FROM art WHERE website LIKE '$website' AND title MATCH(title) AGAINST ('$title') AND DATE_FORMAT(fecha) BETWEEN '$fecsea1' AND '$fecsea2' ORDER BY art_pk DESC", $link);
  14.  
  15.  
  16. ?>


aqui mismo hago update del post para agregar la forma en que quiero que se imprima.
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #5 (permalink)  
Antiguo 05/04/2012, 14:15
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: buscador php para mysql

Actualizo el escrip esta listo pero me da el siguiente error:

Código PHP:
Ver original
  1. <?php
  2.     header('content-type: text/html; charset=utf-8');
  3.     // Si entramos es que todo se ha realizado correctamente
  4.     include("config/config.php");
  5.     $link = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  6.     mysql_select_db($dbname,$link) or die('No se puede seleccionar la base de datos<br>');
  7.     $title=$_POST['title'];
  8.     $website=$_POST['wscb'];
  9.     $fecsea1=$_POST['fecsea1'];
  10.     $fecsea2=$_POST['fecsea2'];
  11.     //busqueda por website-> luego titulo-> luego fecha:
  12.     $result1 = mysql_query("SELECT * FROM art WHERE website LIKE '$website' AND title MATCH(title) AGAINST ('$title') AND DATE_FORMAT(create_date_art) BETWEEN '$fecsea1' AND '$fecsea2' ORDER BY art_pk DESC", $link);
  13.     ?>
  14.     <table border="0" cellspacing="0" cellpadding="0">
  15.         <tr>
  16.             <td width="70">ID</td>
  17.             <td width="400">Title</td>
  18.             <td width="200">Web Site</td>
  19.             <td width="150">Fecha Creacion</td>
  20.             <td width="100">Update Link</td>
  21.         </tr>
  22.     <?php
  23.     //deberia ir un ciclo while dentro de php
  24.     while($printer=mysql_fetch_array($result1)){
  25.     $id = $printer['art_pk'];
  26.     $fecha = $printer['create_date_art'];
  27.     $nombre = $printer['title'];
  28.     $web = $printer['website'];
  29.     ?>
  30.         <tr>
  31.             <td><?php echo " $id "; ?></td>
  32.             <td><?php echo " $nombre"; ?></td>
  33.             <td><?php echo " $web "; ?></td>
  34.             <td><?php echo " $fecha "; ?></td>
  35.             <td> <a href="index4.php">Link</a></td>
  36.         </tr>
  37.     <?php
  38.     }
  39.     //ak terminaria el ciclo While.
  40.     ?>
  41.     </table>
  42.     <?php  
  43.    
  44. ?>

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\liste.php on line 24

alguien puede ayudarme?

..
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #6 (permalink)  
Antiguo 05/04/2012, 14:36
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: buscador php para mysql

intente hacer cambios como:

Código PHP:
Ver original
  1. <?php
  2.     header('content-type: text/html; charset=utf-8');
  3.     // Si entramos es que todo se ha realizado correctamente
  4.     include("config/config.php");
  5.     $link = mysql_connect ($dbhost, $dbusername, $dbuserpass);
  6.     mysql_select_db($dbname,$link) or die('No se puede seleccionar la base de datos<br>');
  7.     $title=$_POST['title'];
  8.     $website=$_POST['wscb'];
  9.     $fecsea1=$_POST['fecsea1'];
  10.     $fecsea2=$_POST['fecsea2'];
  11.     //busqueda por website-> luego titulo-> luego fecha:
  12.     $sql = "SELECT * FROM art WHERE website LIKE '$website' AND title MATCH(title) AGAINST ('$title' IN BOOLEAN MODE) AND DATE_FORMAT(create_date_art) BETWEEN '$fecsea1' AND '$fecsea2' ORDER BY art_pk DESC";
  13.     $arreglo = mysql_query($sql,$link);
  14.     $resultado = mysql_num_rows($arreglo,$link);
  15.     ?>
  16.     <table border="0" cellspacing="0" cellpadding="0">
  17.         <tr>
  18.             <td width="70">ID</td>
  19.             <td width="400">Title</td>
  20.             <td width="200">Web Site</td>
  21.             <td width="150">Fecha Creacion</td>
  22.             <td width="100">Update Link</td>
  23.         </tr>
  24.     <?php
  25.     //deberia ir un ciclo while dentro de php
  26.     while($printer=mysql_fetch_array($resultado)){
  27.     $id = $printer['art_pk'];
  28.     $fecha = $printer['create_date_art'];
  29.     $nombre = $printer['title'];
  30.     $web = $printer['website'];
  31.     ?>
  32.         <tr>
  33.             <td><?php echo " $id "; ?></td>
  34.             <td><?php echo " $nombre"; ?></td>
  35.             <td><?php echo " $web "; ?></td>
  36.             <td><?php echo " $fecha "; ?></td>
  37.             <td> <a href="index4.php">Link</a></td>
  38.         </tr>
  39.     <?php
  40.     }
  41.     //ak terminaria el ciclo While.
  42.     ?>
  43.     </table>
  44.     <?php  
  45.    
  46. ?>

ERRORES

Warning: mysql_num_rows() expects exactly 1 parameter, 2 given in C:\xampp\htdocs\liste.php on line 14

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\liste.php on line 26
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB
  #7 (permalink)  
Antiguo 05/04/2012, 15:00
Avatar de arcanisgk122  
Fecha de Ingreso: junio-2010
Mensajes: 755
Antigüedad: 13 años, 10 meses
Puntos: 28
Respuesta: buscador php para mysql

mande a imprimir el error con:

Código PHP:
Ver original 

y me sales esto:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'MATCH(title) AGAINST ('stock' IN BOOLEAN MODE) AND DATE_FORMAT(create_date_art) ' at line 1
__________________
Cooler Master Gladiator 600 - AMD PHENOM II X4 955 @ 3.5GHZ
GA-MA78GM-US2H - Super Talent 800 2GB x 2 Dual, (Unganged)
PSU Cooler Master eXtreme Power Plus 500W - Saphire R7-260OC-2GB

Etiquetas: html, mysql, sql, buscadores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:51.