I am doing paging with php for my search engine, so far everything is going well, but when I am trying to give the function to the previous button I recive an error related to the variable 'pagina', I am using the GET method and the buttons to change the page On page they work well for me. The data of my query is displayed correctly, everything works for me unless I check the error for the button to return to the previous page.
This is all my code.
<?php
include_once 'conection.php';
$sql = 'SELECT * FROM imagenesAn';
$sentencia = $pdo->prepare($sql);
$sentencia->execute();
$resultado = $sentencia->fetchALL();
$articulos_x_pagina = 10+1;
//contar artículos de nuestra base de datos
$total_articulos_db = $sentencia->rowCount();
$paginas = $total_articulos_db / 10;
$paginas = ceil($paginas);
$salida = "";
$query = "SELECT * FROM imagenesAn WHERE nombre NOT LIKE '' ORDER By id DESC LIMIT $articulos_x_pagina ";
if (isset($_POST['consulta'])) {
$q = $conn->real_escape_string($_POST['consulta']);
$query = "SELECT * FROM imagenesAn WHERE Id LIKE '%$q%' OR nombre LIKE '%$q%' OR nombre_imagen OR registro LIKE '%$q%'";
}
if ($resultado AND $resultado->num_rows>0) {
$salida.="<table class='table table-borderless tabla table-responsive-sm' style='width: 92%; margin-left: 100px; margin-top: 40px; text-align: center;'>
<thead class='jeder'>
<tr class='text-primary'>
<th scope='col text-primary'>ID</th>
<th scope='col'>Nombre</th>
</tr>
</thead>
<tbody class='cuerpo'>";
//var_dump($resultado);
foreach($resultado as $articulo):
$salida.="
<tr>
<td style='text-align: center;'>".$articulo['id']."</td>
<td style='text-align: center;'>".$articulo['nombre']."</td>
<td style='text-align: center;'><a href='diagnostico?id=". $articulo['id']."'><i class='fas fa-file-medical-alt fa-2x' style='color: #c80000'></i></a></td>
</tr>";
endforeach;?>
<div class="contenedorPaginacion">
<nav aria-label="Paginación" class="paginacion">
<ul class="pagination">
<li class="page-item">
<a class="page-link"
/*This is the "76 line"*/ href="buscador.php?pagina=<?php echo $_GET['pagina']-1 ?>">
Anterior
</a>
</li>
<?php for($i = 0;$i<$paginas;$i++){ ?>
<li class="page-item">
<a
href="buscador.php?pagina=<?php echo $i+1?>" class="page-link">
<?php echo $i+1?>
</a>
</li>
<?php }?>
<li class="page-item">
<a href="#" class="page-link">Siguiente</a>
</li>
</ul>
</nav>
</div>
<?php
$salida.="</tbody></table>";
}else{
$salida.="<p class='parrafo' style='margin-left: 10px;'>No se encontraron resultados similares a su busqueda</p>";
}
echo $salida;
$conn->close();
?>
I follow this youtube tutorial https://www.youtube.com/watch?v=d8odPbC8Yhk&t=481s
This is the error: ( ! ) Notice: Undefined index: pagina in C:\Proyecto\buscar.php on line 76 Call Stack #TimeMemoryFunctionLocation 10.0006422336{main}( )...\buscar.php:0 -1"> Anterior