Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/03/2014, 12:13
chubse
 
Fecha de Ingreso: marzo-2012
Mensajes: 84
Antigüedad: 12 años, 2 meses
Puntos: 3
Guardar filtros en una consulta MySQL

Que tal amigos del foro, les agradezco el tiempo y ayuda que siempre brindan a todos. Tengo un problema:
cuando hago un filtro en una consulta a través de un textbox todo funciona perfecto, pero si después de ese filtro quiero hacer otro filtro me borra el anterior y hace el nuevo, entonces lo que quiero hacer es que el primero se almacene y el segundo filtro se haga sobre el primero, y si hago un tercero se haga sobre el primero y segundo y así hasta que decida borrar los filtros.

Les dejo mis códigos esperando que me puedan ayudar.
Gracias

Textbox para filtrar
Código PHP:
<?php
    
    $busqueda
=$_GET["busqueda"];
    
    if (
$_REQUEST["btnBuscar"]!="" && $_REQUEST["busqueda"]!="")
    {
        if (
$_REQUEST["busqueda"])
        
        
$filtro=" AND (
        CASE 
        WHEN (CONCAT_WS(' ',cat_organizacion.opcion, cat_muestra.lista_muestra) = '$busqueda')
        THEN CONCAT_WS(' ',cat_organizacion.opcion, cat_muestra.lista_muestra) like '%"
.$_REQUEST["busqueda"]."%'
        WHEN (CONCAT_WS(' ',cat_muestra.lista_muestra, cat_organizacion.opcion) = '$busqueda')
        THEN CONCAT_WS(' ',cat_muestra.lista_muestra, cat_organizacion.opcion) like '%"
.$_REQUEST["busqueda"]."%'
        WHEN (cat_organizacion.opcion = '$busqueda')
        THEN (cat_organizacion.opcion) like '%"
.$_REQUEST["busqueda"]."%'
        WHEN (cat_muestra.lista_muestra = '$busqueda')
        THEN (cat_muestra.lista_muestra) like '%"
.$_REQUEST["busqueda"]."%'    
        END 
        ) "
;
        
        
$quitar_filtro'<a href="admin_txt.php">Quitar búsqueda</a>';
    
    } else {        
        
        
$mensaje'Escriba la palabra que desea filtrar';
    
    }
    
    echo 
'<form action="admin_txt.php" id="form2" name="form2" method="GET">        
    <table width="100%" border="0">    
    <tr>
    <td colspan="2"><font style="font-size:14px; font-family:Arial">Escribe la(s) palabra(s) que deseas buscar</td>
    </tr>
    <tr>
    <td width="50%"><input type="text" name="busqueda" id="busqueda" value="'
.$busqueda.'" /></font></td>                      
    <td width="50%"><input type="submit" name="btnBuscar" id="btnBuscar" value="Buscar"></input>
    <font size="-2"><font face="Arial">'
.$mensaje.' ';    
    echo 
$quitar_filtro;
    echo 
'</td>
    </tr>    
    </table><br><br>
    </form></font>'
;    
    
    
?>
Consulta
Código PHP:
<?php
  
  $q_citas 
mysql_query " SELECT 
  cat_organizacion.opcion, 
  cat_organizacion.logo,
  cat_muestra.lista_muestra, 
  dat_admin_txt.id_txt     
  FROM dat_admin_txt 
  INNER JOIN cat_muestra ON cat_muestra.id_lista_muestra = dat_admin_txt.id_lista_muestra 
  INNER JOIN cat_organizacion ON cat_organizacion.id = cat_muestra.id_organizacion 
  WHERE dat_admin_txt.id_usuario = '"
.$_SESSION[idusuario]."' ".$filtro.
  ORDER BY cat_organizacion.opcion, cat_muestra.lista_muestra ASC " 
);

?>
Datos
Código HTML:
Ver original
  1. <table width="100%" border="0">
  2.   <tr align="center" id="style_cita_tab_titulos">
  3.     <td width="5%">&nbsp;</td>
  4.     <td width="25%">Nombre organización</td>
  5.     <td width="20%">Muestra</td>
  6.     <td width="5%">&nbsp;</td>
  7.     <td width="5%">&nbsp;</td>
  8.   </tr>
  9.  
  10. <?php while ( $r_citas = mysql_fetch_row ($q_citas) ) { ?>
  11.  
  12. <tr align="center" id="style_cita_tab_opciones">
  13.     <td width="5%"><?php if($r_citas[1] == "") { ?><img src="images/foto_empresa.jpg" width="25" height="25" /><?php }else{ ?><img src="<?php echo $r_citas[1]; ?>" width="25" height="25" /><?php } ?></td>
  14.     <td width="25%"><?php echo $r_citas[0]; ?></td>
  15.     <td width="20%"><?php echo $r_citas[2]; ?></td>
  16.     <td width="5%"><a href="admin_txt_edit.php?cod=<?php echo $r_citas[3]; ?>"><img src="images/actualizar.png" width="15" height="15" title="Actualizar" /></a></td>
  17.     <td width="5%"><a href="reg_cat_txt_elim.php?cod=<?php echo $r_citas[3]; ?>"><img src="images/tache.png" width="15" height="15" title="Eliminar" /></a></td>
  18.   </tr>