86 lines
2.5 KiB
PHP
Raw Normal View History

2021-09-02 08:27:03 -03:00
<?php
session_start();
include_once("../conexao.php");
include('../menu.php');
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Categorias</title>
<link rel="stylesheet" href="../css/menu.css">
<link rel="stylesheet" href="../css/tables.css">
</head>
<body>
<?php echo $nav;?>
<section>
<?php if(isset($_SESSION['msg'])){?>
<div class="msg">
<?php echo $_SESSION['msg'];
unset($_SESSION['msg']);?>
</div>
<?php }?>
<a href="cad_cat.php">Cadastrar</a><br>
<h1>Listar Categorias</h1>
<table border="1" width="100%">
<tr>
<td></td>
<td>Categoria</td>
<td colspan='2'>Operações</td>
</tr>
<?php
$pagina_atual = filter_input(INPUT_GET,'pagina', FILTER_SANITIZE_NUMBER_INT);
$pagina = (!empty($pagina_atual)) ? $pagina_atual : 1;
$qnt_result_pg = 15;
$inicio = ($qnt_result_pg * $pagina) - $qnt_result_pg;
$result_usuarios = "SELECT * FROM categoria LIMIT $inicio, $qnt_result_pg";
$resultado_usuarios = mysqli_query($con, $result_usuarios);
while($row = mysqli_fetch_assoc($resultado_usuarios)){
echo "<tr><td>" . $row['id'] . "</td><td> ";
echo $row['categoria'] . "</td><td> <a href='edit_cat.php?id=". $row['id'] . "'>Editar</a>";
echo "</td><td> <a href='del_cat.php?id=". $row['id'] . "'>Excluir </a></td></tr>";
}
echo "</table>";
$result_pg = "SELECT COUNT(id) AS num_result FROM categoria";
$resultado_pg = mysqli_query($con, $result_pg);
$row_pg = mysqli_fetch_assoc($resultado_pg);
$quantidade_pg = ceil($row_pg['num_result'] / $qnt_result_pg);
$max_links = 2;
echo "<a href='index.php?pagina=1'>Primeira</a> ";
$paginant = $pagina - 1;
$pagprox = $pagina + 1;
if($paginant >= 1)
{
echo "<a href='index.php?pagina=$paginant'><<</a> ";
}
for($pag_ant = $pagina - $max_links; $pag_ant <= $pagina - 1; $pag_ant++){
if($pag_ant >= 1){
echo "<a href='index.php?pagina=$pag_ant'>$pag_ant</a> ";
}
}
echo "$pagina ";
for($pag_dep = $pagina + 1; $pag_dep <= $pagina + $max_links; $pag_dep++){
if($pag_dep <= $quantidade_pg){
echo "<a href='index.php?pagina=$pag_dep'>$pag_dep</a> ";
}
}
if($pagprox <= $quantidade_pg)
{
echo "<a href='index.php?pagina=$pagprox'>>></a> ";
}
echo "<a href='index.php?pagina=$quantidade_pg'>Última</a>";
?>
</section>
<?php echo $footer;?>
</body>
</html>