-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
97 lines (73 loc) · 2.06 KB
/
index.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
<?php require_once "init.php";?>
<?php
$allphotos = "SELECT * FROM photos";
$t_photos = mysqli_query($connection, $allphotos);
$total_photos = mysqli_num_rows($t_photos);
$result_per_page = 3;
$total_pages = ceil($total_photos / $result_per_page);
if (!isset($_GET['page'])) {
$page = 1;
$_GET['page'] = 1;
} else {
$page = $_GET['page'];
}
$this_page_result = ($page - 1) * $result_per_page;
$query = "SELECT * FROM photos LIMIT " . $this_page_result . "," . $result_per_page;
$result = mysqli_query($connection, $query);
if (!$result) {
die("Query failed" . mysqli_error($connection));
}
function nexts()
{
return $_GET['page'] + 1;
}
function previous()
{
return $_GET['page'] - 1;
}
?>
<!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>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main">
<?php while ($photo = mysqli_fetch_array($result)): ?>
<?php
$title = $photo['title'];
$image = $photo['image'];
?>
<div class="inner-main">
<div class="title">
<h4><?php echo $title; ?></h4>
</div>
<div class="img">
<img src="images/<?php echo $image; ?>" alt="">
</div>
</div>
<?php endwhile;?>
</div>
<div class="pagination">
<?php if (previous()): ?>
<a class="pagination_count" href="?page=<?php echo previous(); ?>">Previous</a>
<?php endif;?>
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<?php if ($_GET['page'] == $i) {?>
<a href="?page=<?php echo $i; ?>" class="pagination_count bg-active"><?php echo $i; ?></a>
<?php } else {?>
<a href="?page=<?php echo $i; ?>" class="pagination_count"><?php echo $i; ?></a>
<?php }?>
<?php endfor;?>
<?php if ($total_pages >= nexts()): ?>
<?php if (nexts()): ?>
<a class="pagination_count" href="?page=<?php echo nexts(); ?>">Next</a>
<?php endif;?>
<?php endif;?>
</div>
</body>
</html>