Ver Mensaje Individual
  #7 (permalink)  
Antiguo 12/12/2014, 11:09
pepu
 
Fecha de Ingreso: junio-2005
Mensajes: 69
Antigüedad: 18 años, 10 meses
Puntos: 0
Respuesta: buscador con filtro desde diferentes tablas

No logro crear la pagina que recoge los datos y los muestra las casillas activas en el formulario.
En un formulario cuyas casillas siempre son las mismas (no son leidas de una tabla de la db) y la pagina de resultados recoge eso datos no tengo problema.

Pero no llego al querer mostrar los productos (tabla productos) que pertenezcan a los diferentes grupos, categorias o marcas (tabla filtros) y teniendo en cuenta que para que un producto sea de un grupo, categoria... debe estar en la tabla filtro_rel con el campo activ=1

Por favor si alguien me puede orientar con esta pagina de resultados que coge los datos del formulario y luego hace el select se lo agradezco.

Estas son las llamadas que hago en la pagina buscar
Código PHP:
<?php require_once('../Connections/conect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_conect$conect);
$query_Recordset1 "SELECT * FROM productos ORDER BY hnombre ASC";
$Recordset1 mysql_query($query_Recordset1$conect) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_select_db($database_conect$conect);
$query_Recordgrupos "SELECT * FROM filtros WHERE tipo LIKE '%grupos%' ORDER BY Id_filtro ASC";
$Recordgrupos mysql_query($query_Recordgrupos$conect) or die(mysql_error());
$row_Recordgrupos mysql_fetch_assoc($Recordgrupos);
$totalRows_Recordgrupos mysql_num_rows($Recordgrupos);

mysql_select_db($database_conect$conect);
$query_Recordmarca "SELECT * FROM filtros WHERE tipo LIKE '%marca%'";
$Recordmarca mysql_query($query_Recordmarca$conect) or die(mysql_error());
$row_Recordmarca mysql_fetch_assoc($Recordmarca);
$row_Recordmarca mysql_fetch_assoc($Recordmarca);
$totalRows_Recordmarca mysql_num_rows($Recordmarca);

mysql_select_db($database_conect$conect);
$query_Recordcateg "SELECT * FROM filtros WHERE tipo LIKE '%categoria%'";
$Recordcateg mysql_query($query_Recordcateg$conect) or die(mysql_error());
$row_Recordcateg mysql_fetch_assoc($Recordcateg);
$totalRows_Recordcateg mysql_num_rows($Recordcateg);
?>
ESTE ES EL FORMULARIO QUE ME ENVIA LOS DATOS POR EN LA URL(coge todos los datos de la trabla filtros segun las consultas anteriores)
Código HTML:
 <form action="resultados.php" method="get"> <div class="relative">
										<fieldset>
										
										<h6>GRUPOS</h6>
								<ul>
												<?php do { ?>
												  <li class="m_bottom_2">
												    <input type="checkbox" name="<?php echo $row_Recordgrupos['id_filtro']; ?>" id="<?php echo $row_Recordgrupos['id_filtro']; ?>" value="1">
												    <label for="<?php echo $row_Recordgrupos['id_filtro']; ?>" class="nomcasilla"><?php echo $row_Recordgrupos['nombre']; ?></label>
											    </li>
												  <?php } while ($row_Recordgrupos = mysql_fetch_assoc($Recordgrupos)); ?>
								</ul>
											
										
										</fieldset>
									</div>
									
                                    <div class="relative">
										<fieldset>
									<h6>Categorías</h6>
    							<ul>
									<?php do { ?>
											    <li class="m_bottom_2">
												    <input type="checkbox" name="<?php echo $row_Recordcateg['id_filtro']; ?>" id="<?php echo $row_Recordcateg['id_filtro']; ?>"  value="1">
												    <label for="<?php echo $row_Recordcateg['id_filtro']; ?>" class="nomcasilla"><?php echo $row_Recordcateg['nombre']; ?></label>	
												    </li>
												  <?php } while ($row_Recordcateg = mysql_fetch_assoc($Recordcateg)); ?>

									
								</ul>
											
										
										</fieldset>
									</div>
                                    
                                    <div class="relative">
										<fieldset>
										
										<h6>Marcas</h6>
								
								<ul>
																								<?php do { ?>
								    <li class="m_bottom_2">
									    <input type="checkbox" name="<?php echo $row_Recordmarca['id_filtro']; ?>" id="<?php echo $row_Recordmarca['id_filtro']; ?>" value="1">
									    <label for="<?php echo $row_Recordmarca['id_filtro']; ?>" class="nomcasilla"><?php echo $row_Recordmarca['nombre']; ?></label>	
								      </li>
									  <?php } while ($row_Recordmarca = mysql_fetch_assoc($Recordmarca)); ?>
								</ul>
											
											
										</fieldset>
									</div>

									<button type="sent">Filtrar</button>
								</form> 

Con esto logro que la pagina resultados venga del siguiente modo
resultados.php?1=1&4=1&5=1&8=1
con lo cual el filtro con id_filtro=1,4,5 y 8 ha sido marcado por el usuario en el formulario. Los otros no han sido marcados


Ahora, despues de muchos intentos sigo liado con la pagina de resultados

Debo coger esa url con los id_filtros marcados y relacionarlo con la tabla filtros_rel para mostrar los productos.

Por favor alguna orientación?

ESTA SON LAS TABLAS

Código:
--
-- Estructura de tabla para la tabla `filtros`
--

CREATE TABLE IF NOT EXISTS `filtros` (
`id_filtro` int(11) NOT NULL,
  `nombre` varchar(255) COLLATE utf8_spanish_ci DEFAULT NULL,
  `tipo` varchar(255) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;



--
-- Estructura de tabla para la tabla `filtro_rel`
--

CREATE TABLE IF NOT EXISTS `filtro_rel` (
`id_relacion` int(11) NOT NULL,
  `id_producto` int(11) NOT NULL,
  `id_filtro` int(11) NOT NULL,
  `activ` int(2) NOT NULL DEFAULT '0'
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;



-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `productos`
--

CREATE TABLE IF NOT EXISTS `productos` (
`id_producto` int(11) NOT NULL,
  `hcodigo` varchar(15) COLLATE utf8_spanish_ci NOT NULL DEFAULT '',
  `hnombre` varchar(250) COLLATE utf8_spanish_ci DEFAULT NULL,
  `hpresentacion` varchar(250) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=97 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;



--
-- Filtros para la tabla `filtro_rel`
--
ALTER TABLE `filtro_rel`
ADD CONSTRAINT `rest_filtros` FOREIGN KEY (`id_filtro`) REFERENCES `filtros` (`Id_filtro`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `rest_prod` FOREIGN KEY (`id_producto`) REFERENCES `productos` (`id_producto`) ON DELETE NO ACTION ON UPDATE NO ACTION;