Good afternoon, I have the following menu:
I would like to click on each category to show only the products of that category, but not to show me the products shows me those errors, the code is the following for the logic:
<?php
include 'conexion.php';
//Traer las categorias desde la base de datos
$consulta = $conexion->prepare("SELECT * FROM tcategoria");
$consulta->execute();
$categorias = $consulta->fetchAll();
if(!$conexion){
die();
}
$idCat=isset($_GET['idCategoria']) ? (int) ($_GET['idCategoria']) : false;
if(!$idCat){
header('Location: index.php');
}
$statement=$conexion->prepare('SELECT * FROM tproducto WHERE idCategoria = :idCat');
$statement->execute(array(':idCat' => $idCat));
$categoria=$statement->fetch();
if(!$categoria){
header('Location: index.php');
}
include 'views/listacategorias.view.php';
?>
And the next one for the view:
<div class="catprod">
<nav class="categorias col-3 col-m-4">
<ul>
<?php foreach($categorias as $categoria): ?>
<li><a href="listacategorias.php?idCategoria=<?php echo $categoria['idCategoria']; ?>"><?php echo $categoria['Categoria']; ?></a></li>
<?php endforeach; ?>
</ul>
</nav>
<article class="imagenes col-9 col-m-8">
<?php foreach($categoria as $cat):?>
<div class="imagen1 col-4 col-m-6">
<h2><?php echo $cat['Producto']; ?></h2>
<a href="fotos.php?idProducto=<?php echo $foto['idProducto']; ?>">
<img src="albumProductos/<?php echo $cat['Imagen'] ?>" alt="<?php echo $cat['Descripcion'] ?>">
</a>
<p><b>$: </b><?php echo $cat['Precio']; ?></p>
<span class="icon-shopping-cart"></span><input type="submit" value="Comprar">
</div>
<?php endforeach;?>
</article>
<div class="paginacion imagenes">
<?php if($pagina_actual > 1): ?>
<a href="index.php?p=<?php echo $pagina_actual - 1; ?>" class="izquierda col-6 col-m-6"><span class="icon-arrow-left-alt1"></span> Página Anterior</a>
<?php endif ?>
<?php if($total_paginas != $pagina_actual): ?>
<a href="index.php?p=<?php echo $pagina_actual + 1; ?>" class="derecha col-6 col-m-6">Página Siguiente <span class="icon-arrow-right-alt1"></span></a>
<?php endif ?>
</div>
</div>
I hope you can help me, thank you.