Good afternoon, when trying to bring images from the database the page sends me the following errors:
Notice: Undefined variable: photos in C: \ xampp \ htdocs \ projectCarrito2 \ views \ index.view.php on line 72 Warning: Invalid argument supplied for foreach () in C: \ xampp \ htdocs \ projectCarrito2 \ views \ index.view.php on line 72
In the part of the index.php
I have the following code:
<?php
session_start();
if(empty($_SESSION['idUsuario']) && empty($_SESSION['Tipo'])){
include 'conexion.php';
include 'views/index.view.php';
$fotos_por_pagina = 16;
$pagina_actual = (isset($_GET['p']) ? (int)$_GET['p'] : 1);
$inicio = ($pagina_actual > 1) ? $pagina_actual * $fotos_por_pagina - $fotos_por_pagina : 0;
$conexion = conexion('proyecto', 'root', '');
if (!$conexion) {
die();
}
$statement = $conexion->prepare("
SELECT SQL_CALC_FOUND_ROWS * FROM timagen LIMIT $inicio, $fotos_por_pagina
");
$statement->execute();
$fotos = $statement->fetchAll();
if (!$fotos) {
header('Location: index.php');
}
$statement = $conexion->prepare("SELECT FOUND_ROWS() as total_filas");
$statement->execute();
$total_post = $statement->fetch()['total_filas'];
$total_paginas = ceil($total_post / $fotos_por_pagina);
}else{
header("Location: formularios/form_cliente.php");
}
?>
And in the part of the view that is index.view.php I have the following:
<article class="imagenes col-9 col-m-8">
<?php foreach($fotos as $foto):?>
<div class="col-4 col-m-6">
<a href="fotos.php?id=<?php echo $foto['idImagen']; ?>">
<img src="images/bd<?php echo $foto['Imagen'] ?>" alt="<?php echo $foto['Descripcion'] ?>">
</a>
</div>
<?php endforeach;?>
</article>
I hope you can help me. Thanks.