-1
Help me out, guys!!!
$BuscaProdutosAtivos = $pdo->prepare("SELECT * FROM tbl_produtos p
INNER JOIN tbl_categorias c ON c.cat_id = p.prod_categoria
INNER JOIN tbl_variacoes v ON v.cod_prod = p.id
WHERE p.prod_ativo = 1");
////////////////////////////////
$BuscaProdutosAtivos->execute();
$BuscaProdutosAtivos->rowCount();
I’m searching for 3 types of information within the database: first I search for a product that is active to show in the store, so far so good.
Then I look for the category to which this product belongs and also everything goes well.
My product can be green, yellow or blue and that’s what I look for in the table tbl_variacoes
and try to put inside a dropdown and that’s where I have trouble because it returns only the first variation, ie only the first color.
while($PA = $BuscaProdutosAtivos->fetch()){ ?>
<select name="variacoes" class="form-control chosen-select" data-placeholder="Escolha a variação">
<option value=""></option>
<option value="1"><?=$PA['cor']?></option>
</select>
?>
How to return all variations within the dropdown?
This code returns to me all base products that meet the requirements. If you can help me understand !!!!
Running the query directly in Mysql the expected records are returned?
– Marcio Mazzucato
There is no mistake!!! Only in the dropdown list it only takes the first variation. Actually this while is to list all the products, so I think you need to do something else to return the variations. I made an update of the question by placing full code link.
– Marcos Vinicius
The query is returning perfectly what it should return which is all active products with at least one category and one variation. All that remains is to return ALL variations.
– Marcos Vinicius
Review this
JOIN
, apparently he’s wrong:INNER JOIN tbl_variacoes v ON v.var_id = p.prod_categoria
, you are crossing theID
of the variation with theID
of the category– Marcio Mazzucato