Hello, how are you? I bother you with a question?.
I decided to group products according to the subcategory (id_subcate) but when accessing the Category (id_cate)
I start from the base, as well comments and made me realize @amenadiel,
Your query only uses the ID of the main category
that I take the urls via $_GET
and that I am always positioned in the Category productos.php?id_cate=7
there access to a list of all related products but without taxonomic order.
Categories
tbl_categorias id_cate id_catemaster nombre
Products
tbl_productos id_prod id_cate id_subcate id_subnivcate nombre precio
Here the id_subcate is an INT ej. 2
Subcategories
tbl_subcategorías id_subcate, id_cate, nombre
Here the id_subcate is a VARCHAR ex. torso garments
I think I should relate the tables to JOIN and then Echo the name of the subcategory in VARCHAR .-
The following is the scheme that I hope to achieve
Category Title (this I already have)
Subcategory title
Products that correspond to the subcategory
Then a line break <br>
Title of another subcategory
Products that correspond to the subcategory
Then a line break <br>
*
Here the code where I go that only shows the products without order
<?php
$id_prod = $HttpVars->TraerGet('id_prod');
$id_subcate = $HttpVars->TraerGet('id_subcate');
$id_cate = $HttpVars->TraerGet('id_cate');
$id_subnivcate = $HttpVars->TraerGet('id_subnivcate');
if($id_cate != "") {
//sql para titulo de categoria
$sqltit = "SELECT nombre FROM tbl_categorias WHERE id_cate = ".intval($id_cate);
//sql para los productos
$sql = "SELECT P.id_prod, P.nombre, P.filech, P.precio, P.dcorta, P.publicado, P.id_cate, P.id_subcate ";
$sql.= "FROM tbl_productos as P ";
$sql.= "WHERE P.id_cate = ".intval($id_cate)." AND P.publicado = 1 and P.borrado = 0 ";
$sql.= "ORDER BY P.id_subcate";
}
$resulttit = $db->Query($sqltit,$connection);
$myrowtit = mysqli_fetch_array($resulttit, MYSQLI_BOTH);
?>
<div class="titcate"><p><?php echo $myrowtit["nombre"]; ?></p></div>
<div class="clear"></div>
<?php
$result = $db->Query($sql,$connection);
$totreg = mysqli_num_rows($result);
if ($db->CantidadFilas($result) > 0){
$cont=0;
while ($myrow = mysqli_fetch_array($result, MYSQLI_BOTH)) {
$precio = $myrow["precio"];
$nombre = $myrow["nombre"];
$cont++;
$imagen = $myrow["filech"];
$id_prod = $myrow["id_prod"];
if($imagen == "") {
$imagen = "noimagen.gif";}
?>
<div class="productoshome">
<p id="tit_prod"><? echo $nombre;?> </p>
<a title="<? echo $nombre ?>" href="<? echo "producto.php?id_prod=$id_prod/" ?>"></a>
<img src="timthumb.php?src=imgprod/<? echo $myrow['filech'] ?>&h=178&w=188&zc=1" alt="<? echo $nombre ?>" title="<? echo $nombre ?>" />
<p id="precio_prods">$ <? echo $precio ?></p>
</div>
<?php
}
}
else {
echo "<p>No hay productos disponibles para esta categoría. <a href='index.php'>Haga click aquí para seguir navegando</a></p>";
}
?>
This for now, several days ago I try to find the right logic .. thanks