1
Good morning Guys, I have this query
$query = "SELECT p.*, c.nomeCategoria AS categoria FROM produto AS p INNER JOIN produto_categoria AS c";
$dados = mysqli_query($con, $query) or die(mysqli_error());
and a while that returns the value within a select.
<select name="categoriaProduto">
<?php
while($row = mysqli_fetch_array($dados))
{
?>
<option value="<?php echo $row["categoria"]; ?>"><?php echo $row["categoria"]; ?></option>
<?php
}
?>
</select>
only that on my page it is showing the duplicated select data, I have 3 items registered in the table categoria_product.
I was wondering if there was anything I did wrong with the code. Thank you!!
This combo is only to display categories? if it is not necessary to Inner Join just a simple select.
– rray
Would then
select nomeCategoria FROM categoria_produto
? is that in fact, this is the registration of products, and the combo really is only to show the registered categories, but the one that is chosen in the combo, will have the code saved in the product table.– Danillo Villas Neto
you don’t have a table only for categories?
– rray
You have to have two queries. One for product data and one for categories. If you make a Join you need to specify the link columns with the
ON
. See in the documentation how to perform an Inner Join.– Waldir J. Pereira Junior
@Yeah, I got it. table products, where it has a column "categoriaProduct" of type int, and the table categoria_products where have the columns "idCategory" and "Category name".
– Danillo Villas Neto
A product has only one category?
– rray
@rray yes, it’s very simple
– Danillo Villas Neto
I get it, so do one
select idCategoria, nomeCategoria FROM categoria_produto
theidCategoria
goes in combo value andnomeCategoria
goes within the option.– rray
@rray thanks man!!! gave right to what I needed!
– Danillo Villas Neto