-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
170 lines (157 loc) · 7.48 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
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
<?php
if (!isset($_GET["rel"]) || $_GET["rel"] !== "page") {
include_once 'includes/header.php';
}
?>
<main>
<div class="page">
<div class="hero">
<?php
$sql = "SELECT * FROM projects ORDER BY RAND() LIMIT 4";
$result = $conn->query($sql);
// Assign each record to a specific card
$card1 = $result->fetch(PDO::FETCH_ASSOC);
$card2 = $result->fetch(PDO::FETCH_ASSOC);
$card3 = $result->fetch(PDO::FETCH_ASSOC);
$card4 = $result->fetch(PDO::FETCH_ASSOC);
?>
<div class="d-grid-col hero-main">
<div class="grid-left">
<div class="left-image">
<div class="image">
<img src="/images/<?php echo $card1['image_name']?>" alt="">
<span><?php echo $card1['title']?></span>
<div class="gradient-overlay"></div>
</div>
</div>
</div>
<div class="grid-right">
<div class="d-grid-row">
<div class="upper">
<div class="upper-img">
<div class="image">
<img src="/images/<?php echo $card2['image_name']?>" alt="">
<span><?php echo $card2['title']?></span>
<div class="gradient-overlay"></div>
</div>
</div>
</div>
<div class="d-grid-col">
<div class="hero-col">
<div class="col-content">
<div class="image">
<img src="/images/<?php echo $card3['image_name']?>" alt="">
<span><?php echo $card3['title']?></span>
<div class="gradient-overlay"></div>
</div>
</div>
</div>
<div class="hero-col">
<div class="col-content">
<div class="image">
<img src="/images/<?php echo $card4['image_name']?>" alt="">
<span><?php echo $card4['title']?></span>
<div class="gradient-overlay"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<section>
<div class="projects-section">
<div class="project-left">
<div class="title-section">
<span>Recently Updated</span>
</div>
<div class="card-container">
<?php
$limit = 6; // Number of projects per page
$currentPage = isset($_GET['page']) ? $_GET['page'] : 1; // Get the current page from the URL
$offset = ($currentPage - 1) * $limit; // Calculate the offset
$getProjects = $conn->prepare('SELECT * FROM projects LIMIT :limit OFFSET :offset');
$getProjects->bindParam(':limit', $limit, PDO::PARAM_INT);
$getProjects->bindParam(':offset', $offset, PDO::PARAM_INT);
$getProjects->execute();
while ($project = $getProjects->fetch(PDO::FETCH_ASSOC)) {
$dateCreatedArr = new DateTime($project['created_at']);
$dateCreated =$dateCreatedArr->format('F j, Y, g:i a');
?>
<div class="card">
<a class="card-link" href="download.php?project=<?php echo $project['title']?>">
<img src="/images/<?php echo $project['image_name'] ?>" alt="">
<div class="card-content">
<p><?php echo $project['title']; ?></p>
<p>Posted on: <?php echo $dateCreated ?></p>
<a class="view-more" href="download.php?project=<?php echo $project['title']?>">View More</a>
<span><?php echo $project['language']; ?></span>
<!-- Add other project information as needed -->
</div>
</a>
</div>
<?php
}
?>
</div>
<div class="navigation pagination">
<?php
// Pagination links
$totalProjects = $conn->query('SELECT COUNT(*) FROM projects')->fetchColumn();
$totalPages = ceil($totalProjects / $limit);
$startPage = max(1, $currentPage - 1);
$endPage = min($totalPages, $startPage + 2);
if ($startPage > 1) {
?>
<div class="pagination-link nav-to-page">
<span><a href="?page=1">1</a></span>
</div>
<?php
if ($startPage > 2) {
?>
<div class="pagination-link">
<span>...</span>
</div>
<?php
}
}
for ($i = $startPage; $i <= $endPage; $i++) {
$activeClass = ($i == $currentPage) ? 'active' : '';
?>
<div class="pagination-link nav-to-page <?php echo $activeClass; ?>">
<span><a href="?page=<?php echo $i; ?>"><?php echo $i; ?></a></span>
</div>
<?php
}
if ($endPage < $totalPages) {
if ($endPage < $totalPages - 1) {
?>
<div class="pagination-link">
<span>...</span>
</div>
<?php
}
?>
<div class="pagination-link nav-to-page">
<span><a href="?page=<?php echo $totalPages; ?>"><?php echo $totalPages; ?></a></span>
</div>
<?php
}
?>
</div>
</div>
<?php
include_once 'includes/project-right.php'
?>
</div>
</div>
</section>
</div>
</main>
<?php if ($_GET["rel"] != "page") {
echo "</div>";
} ?>
<?php
include_once 'includes/footer.php';
?>