0
I am developing a product page that lists within each category all related products (they are various categories and various products). Like the code below, it 'rotates' all the categories and what I need to do, and where I need help, is to list the products.
<?php do { ?> //Listagem das Categorias
<div class="row" id="<?php echo $row_ListaCategoria['descricao'];?>">
<div class="header-content">
<!--CATEGORIA-->
<div class="separador"><!--Nome da Categoria-->
<h3><?php echo $row_ListaCategoria['descricao']; ?></h3>
<hr/>
</div>
<!--PRODUTOS--><!--Rodar todos os produtos da categoria $row_ListaCategoria['id']-->
<div class="col-lg-3 col-md-3 col-xs-12 col-sm-6 col-lg-3-edit thumb">
<div class="box clearfix">
<!--IMAGEM PRODUTO-->
<a href="img/produtos/id/101.1032.png" class="thumbnail text-center thumbnail-edit thumbnail_wrapper no-border-radius pop" data-toggle="lightbox" data-title="CHICOTE PARA REPARO ALTERNADOR VW/CHICOTE P/REPARO SENSOR PRESS" data-footer="TC Chicotes">
<img class="img-responsive img-form-edit" src="img/produtos/id/101.1032.png" alt="#" />
</a>
<!--INFORMAÇÕES PRODUTO-->
<div class="product-text">
<h4>CHICOTE PARA REPARO ALTERNADOR VW/CHICOTE P/REPARO SENSOR PRESS</h4>
<p><strong>Código:</strong> 101.1152<br>
<strong>Aplicação:</strong> 400<br>
<strong>Obs:</strong> N/F</p>
</div>
</div>
</div>
</div>
</div>
<?php } while ($row_ListaCategoria = mysql_fetch_assoc($ListaCategoria)); ?>
To find the categories I use:
mysql_select_db($database_Conect, $Conect);
$query_ListaCategoria = sprintf("SELECT * FROM tbl_categoria WHERE id_empresa = %s ORDER BY descricao", GetSQLValueString($colname_listaFabrica, "int"));
$ListaCategoria = mysql_query($query_ListaCategoria, $Conect) or die(mysql_error());
$row_ListaCategoria = mysql_fetch_assoc($ListaCategoria);
$totalRows_ListaCategoria = mysql_num_rows($ListaCategoria);
Bench:
(Category)
`id` int(11) NOT NULL AUTO_INCREMENT,
`descricao` varchar(32) NOT NULL,
`data_cadastro` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`id_empresa` int(11) NOT NULL,
PRIMARY KEY (`id`)
(Enterprise)
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(100) NOT NULL,
`data_cadastro` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`ativo` int(1) NOT NULL,
PRIMARY KEY (`id`)
(Product)
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(255) NOT NULL,
`tbl_categoria_id` int(11) NOT NULL,
`tbl_empresa_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`tbl_categoria_id`)
REFERENCES tbl_categoria(id)
ON DELETE CASCADE,
FOREIGN KEY (`tbl_empresa_id`)
REFERENCES tbl_empresa(id)
ON DELETE CASCADE
An example of how it would be shown:
I couldn’t solve this problem yet, I tried to develop a Function to select the products but it hasn’t worked yet. I’m open if you have any suggestions, ideas or solutions.
I thank you all in advance!
Why don’t you create the selects according to your categories? Ex.: select * from product p Where p.categoria='Parts cars' - select * from product p Where p.categoria='Parts bikes'. ai on your page you print the list inside each category referring to select.
– EA.Jsp.Android
Because it’s a one-represented system, so I have several companies with different categories. Then it’s impossible to select each one. If I don’t get you wrong.
– Lucas
Products and Categories share some key (key) ?
– Fleuquer Lima
Yes, tbl_product has tbl_category ID and tbl_company @Fleuquerlima
– Lucas
To select the category you have already selected the right company? The product would be filtered by the id_company and id_categoria. Your doubt is on how to mount this Query?
– Fleuquer Lima
@Fleuquerlima, yes, that’s right, I’m already selecting the categories according to the company, shows me the categories perfectly, but within each category I need to show all the products of this. I don’t know if it would be done in the same query. At first I tried to do a function that received the category value and selected the products, but it didn’t work. If it is possible to perform in the same query would be great.
– Lucas
Can do in the same Query yes, just need to know what to pass parameter.
– Fleuquer Lima
@Fleuquerlima, right, I updated with more information if you can help me with this query
– Lucas