-
Notifications
You must be signed in to change notification settings - Fork 0
/
buscar.php
207 lines (188 loc) · 6.28 KB
/
buscar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
include "banco.php";
$pdo = Banco::conectar();
$tam = "20"; // Tamanho da imagem e card na página
$alt = "16"; // Altura da imagem
$objeto = $_POST['obj'];
//Somar a quantidade de itens
$result_pg = "SELECT COUNT(id) AS num_result\n"
."FROM receitas\n"
."WHERE titulo LIKE '$objeto'";
$resultado_pg = Banco::conectar()->prepare($result_pg);
$resultado_pg->execute();
$row_pg = $resultado_pg->fetch(PDO::FETCH_ASSOC);
//Setar a quantidade de itens por página
$qtd_result_pg = 3; // era 19 itens
//Quantidade de páginas
$aaa = $row_pg['num_result'];
$quantidade_pg = ceil($aaa / $qtd_result_pg);
//Receber o número da página
$pagina_atual = filter_input(INPUT_GET, 'pagina', FILTER_SANITIZE_NUMBER_INT);
$pagina = (!empty($pagina_atual)) ? $pagina_atual : 1;
//Calcular o início da visualização
$inicio = ($qtd_result_pg * $pagina) - $qtd_result_pg;
if (empty($_GET))
$vari = 1;
else
$vari = $_GET['pagina'];
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" href="img/favicon.png" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<script src="bootstrap/jquery.js"></script>
<style>
img {
width: <?php echo $tam; ?>rem;
height: <?php echo $alt; ?>rem;
}
.card {
margin: 8px 0px 0px 0px;
}
.footer, h2 {
background-color: #F5F5F5;
}
@media screen and (max-width: 400px) {
.card-body {
text-align: right;
}
}
</style>
<title>Buscando por: <?php echo ucwords($objeto); ?></title>
</head>
<body>
<!-- Menu -->
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#me" aria-controls="me" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="me">
<ul class="navbar-nav">
<li>
<a class="navbar-brand" href="index.php">Início <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="navbar-brand dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="criar.php" title="Adicionar nova receita">Cadastrar</a>
<div class="dropdown-divider"></div><!-- Divisor de links no menu -->
<a class="dropdown-item" href="../../" title="Sistema Casa Pessoal">Sistema</a>
<a class="dropdown-item" href="../agenda/index.php" title="Contatos">Agenda</a>
<a class="dropdown-item" href="../">Testes</a>
</div>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0" method="post" action="buscar.php?pagina=1">
<input class="form-control mr-sm-2" type="text" placeholder="Buscar" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Buscar</button>
</form>
</div>
</div>
</nav>
<main role="main">
<!-- Aqui começa a página -->
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1>
Receitas Caseiras
<br/>
Buscando por: <?php echo ucwords($objeto); ?>
</h1>
</div>
</div>
<div class="container">
<div class="row">
<?php
$sql = "SELECT *\n"
. "FROM receitas\n"
. "WHERE titulo LIKE '%$objeto%'\n"
. "ORDER BY titulo ASC\n"
. "LIMIT $inicio, $qtd_result_pg";
foreach($pdo->query($sql) as $row) {
if (strlen($row['titulo']) >= 20)
$string = substr(trim($row['titulo']),0,23)."...";
else
$string = $row['titulo'];
?>
<div class="col-md-4"> <!-- Receita <?php echo $row['id']; ?> -->
<div class="card" style="width: <?php echo $tam; ?>rem;">
<img class="card-img-top" src="<?php echo $row['imagem']; ?>" alt="Imagem de <?php echo ucwords($row['titulo']); ?>" onmouseover="toolTip('<b><?php echo ucwords($row['titulo']); ?></b>')" onmouseout="toolTip()" />
<div class="card-body">
<h5 class="card-title"><b><?php echo ucwords($string); ?></b></h5>
<a href="ler.php?id=<?php echo $row['id']; ?>&pag=<?php echo $pagina; ?>" class="btn btn-secondary">Ver</a>
</div>
</div>
</div>
<?php }
Banco::desconectar();
?>
</div>
</div>
<br/>
<?php if ($quantidade_pg > 1) {
?>
<nav aria-label="Navegação">
<?php
// Paginação
//echo "<p>" . $row_pg['num_result'] . "</p>";
//Limitar a quantidade de Links antes e depois
$max_links = 3;
?>
<ul class="pagination justify-content-center">
<?php if ($vari == 1 || empty($vari)) {
?>
<li class="page-item disabled"><a href="#" class="page-link">«</a></li>
<?php }
elseif ($vari <= $quantidade_pg and $vari >= 1) {
?>
<li class="page-item"><a class="page-link" href="index.php?pagina=1">«</a></li>
<?php
}
elseif ($vari <= 0) {
header("Location: index.php?pagina=1");
}
for ($pag_ant = $pagina - $max_links; $pag_ant <= $pagina - 1; $pag_ant++) {
if ($pag_ant >= 1) { ?>
<li class="page-item"><a class="page-link" href="index.php?pagina=<?php echo $pag_ant; ?>"><?php echo $pag_ant; ?></a></li>
<?php }
}
?>
<li class="page-item disabled"><a href="#" class="page-link"><?php echo $pagina; ?></a></li>
<?php
for ($pag_dep = $pagina + 1; $pag_dep <= $pagina + $max_links; $pag_dep++) {
if ($pag_dep <= $quantidade_pg) { ?>
<li class="page-item"><a class="page-link" href="index.php?pagina=<?php echo $pag_dep; ?>"><?php echo $pag_dep; ?></a></li>
<?php }
}
if ($vari == $quantidade_pg) { ?>
<li class="page-item disabled"><a href="#" class="page-link">»</a></li>
<?php }
elseif ($vari != $quantidade_pg and $vari <= $quantidade_pg) { ?>
<li class="page-item"><a href="index.php?pagina=<?php echo $quantidade_pg; ?>" class="page-link">»</a></li>
<?php }
else {
header("Location: index.php?pagina=$quantidade_pg");
}
?>
</ul>
</nav>
<?php }
?>
<br/>
<?php
rodape();
?>
</main>
<script src="bootstrap/jquery-3.3.1.slim.min.js"></script>
<script>window.jQuery || document.write('<script src="bootstrap/jquery-slim.min.js"><\/script>')</script>
<script src="bootstrap/popper.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
<script src="../../configs/css/tooltip.js"></script>
</body>
</html>