-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
76 lines (69 loc) · 2.63 KB
/
index.php
File metadata and controls
76 lines (69 loc) · 2.63 KB
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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('connection/connection.php');
define('INTERVALO',3);
// totalArtigos = 7
// numPaginas = arredondar para cima(totalArtigos / INTERVALO)
// 1 - limite=3&offset=0
// 2 - limite=3&offset=3
// 3 - limite=3&offset=6
$qArtigos = "SELECT idArtigo,tituloArtigo,textoArtigo,dataArtigo FROM artigos ORDER BY dataArtigo DESC LIMIT ?";
$stmtArtigos = $conn->prepare($qArtigos);
if ($stmtArtigos === FALSE) {
die("Erro no SQL: " . $qArtigos . " Error: " . $conn->error);
}
if (isset($_GET['numArtigos']) && $_GET['numArtigos'] != "") {
$numArtigos = $_GET['numArtigos'];
} else {
$numArtigos = INTERVALO;
}
$stmtArtigos->bind_param('i',$numArtigos);
$stmtArtigos->execute();
$stmtArtigos->store_result();
$totalArtigos = $stmtArtigos->num_rows;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BLOG</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>BLOG</h1>
<h2>Artigos</h2>
<?php
$stmtArtigos->bind_result($idArtigo,$tituloArtigo,$textoArtigo,$dataArtigo);
while ($stmtArtigos->fetch()) {
?>
<div class="card">
<div class="card-header">
<?= $dataArtigo ?>
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p><a href="artigos.php?idArtigo=<?= $idArtigo ?>"><?= $tituloArtigo ?></a></p>
<footer class="blockquote-footer"><?= substr($textoArtigo,0,250) ?>......</footer>
</blockquote>
</div>
</div>
<br>
<?php } ?>
<?php
if ($numArtigos <= $totalArtigos) {
?>
<a href="index.php?numArtigos=<?= $numArtigos+INTERVALO ?>" class="btn btn-primary">Carregar mais artigos...</a>
<?php } else { echo "<h3>Chegou ao final dos artigos!</h3>"; }?>
</div>
<?php
$stmtArtigos->close();
$conn->close();
?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>