I am having difficulty to list products by category, I created only one page and wanted to be dynamic the display of products according to the category listed in the database, but not right and in PDO
do not know how do. So I created a variable and passed the value by GET
and even then it did not work, if someone can help me thank you !!
<p class="titulo-produtos">Produtos..</p>
<ul class="menu-produtos">
<?php
try {
$categorias = $conexao_pdo->prepare("SELECT * FROM categorias ORDER BY nome ASC");
$executa = $categorias->execute();
if($executa){
while($reg = $categorias->fetch(PDO::FETCH_OBJ)){
/* Para recuperar um ARRAY utilize PDO::FETCH_ASSOC */
?>
<li><a href="?categoria=<?php echo $reg->ID;?>"><?php echo $reg->nome?></a></li>
<?php
}//if
}//while
else {
echo 'Erro ao listar as Categorias!!';
}
}//try
catch(PDOException $e){
echo $e->getMessage();
}
?>
</ul><!-- menu-produtos -->
<ul class="produtos-internas">
<?php
$no = 'categoria';
try {
$sql = "SELECT * FROM produtos WHERE categoria = ? AND status = 'on' ORDER BY nome ASC LIMIT 50";
if($produtos = $conexao_pdo->prepare($sql)){
if($produtos->execute(array($no))){
while($reg = $produtos->fetch(PDO::FETCH_OBJ)){
$dados[] = $reg;
}
}
}
} catch(PDOException $e){
echo $e->getMessage();
}
if(isset($dados)){
foreach($dados as $object){
?>
<li>
<a href="#">
<span class="rollover"></span>
<img src="admin/uploads/<?php echo $object->foto; ?>" />
<p>
<?php echo $object->nome ?><br /><br />
Por <span>R$ <?php echo $object->vlor_avista ?>,00</span> á vista<br />
ou 12x de R$ <?php echo $object->vlor_aprazo ?>,00 sem juros
</p>
</a>
</li>
<?php
}
}
?>
</ul><!-- produtos -->
</section><!-- container -->