1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-19 21:43:06 +05:30

(refactor): following core/query_functions approach + (feature): implemented dynamic featured footer section

This commit is contained in:
2023-10-31 23:42:53 +05:30
parent a773bd7b4a
commit 000787ccd4
6 changed files with 80 additions and 43 deletions

View File

@@ -1,32 +1,8 @@
<?php
require './core/connection.php';
require './core/query_functions.php';
$sql = "SELECT DISTINCT year FROM projects ORDER BY year DESC";
$result = $conn -> query($sql);
if ($result) {
// create a array of all unique years
$years = array();
while ($row = $result -> fetch_assoc()) {
$years[] = $row['year'];
}
$result -> free();
}
//function to fetch all projects of the given year
function fetch_projects_by_year($conn, $year) {
$sql = "SELECT * FROM projects WHERE year = $year ORDER BY id DESC";
$result = $conn -> query($sql);
return $result;
}
//function to fetch top 2 featured projects for sidebar
function fetch_featured_projects_sidebar($conn) {
$sql = "SELECT * FROM featured_projects LIMIT 2";
$result = $conn -> query($sql);
return $result;
}
$years = create_project_years_array($conn);
?>
<!DOCTYPE html>
@@ -147,21 +123,30 @@ function fetch_featured_projects_sidebar($conn) {
<div class="w-full flex flex-col justify-center items-center mb-12">
<?php
$featured_projects = fetch_featured_projects_sidebar($conn);
$featured_projects = fetch_featured_projects($conn);
if($featured_projects -> num_rows > 0){
//show top 2 featured projects for sidebar
$counter = 0;
while($featured_item = $featured_projects -> fetch_assoc()) {
echo "
<div class='group w-[250px] rounded-lg overflow-hidden my-3 relative border-accent_three hover:border-[3px] transition-[border-width] transform duration-100'>
<div class='overlay absolute w-full h-full bg-gradient-to-r from-bg_third z-20 flex-col p-3 hidden group-hover:flex'>
<h6 class='text-xl mb-1'>".$featured_item['name']."</h6>
<p class='text-xs font-[300] mb-4 text-accent_three'>".$featured_item['description']."</p>
<a class='text-sm font-[300] bg-gradient-to-r from-accent_secondary_transparent border-[1px] border-accent_secondary px-3 py-[0.15rem] w-fit rounded-full hover:rounded' href='".$featured_item['link']."' target='_blank'>View Now</a>
if ($counter < 2) {
echo "
<div class='group w-[250px] rounded-lg overflow-hidden my-3 relative border-accent_three hover:border-[3px] transition-[border-width] transform duration-100'>
<div class='overlay absolute w-full h-full bg-gradient-to-r from-bg_third z-20 flex-col p-3 hidden group-hover:flex'>
<h6 class='text-xl mb-1'>".$featured_item['name']."</h6>
<p class='text-xs font-[300] mb-4 text-accent_three'>".$featured_item['description']."</p>
<a class='text-sm font-[300] bg-gradient-to-r from-accent_secondary_transparent border-[1px] border-accent_secondary px-3 py-[0.15rem] w-fit rounded-full hover:rounded' href='".$featured_item['link']."' target='_blank'>View Now</a>
</div>
<img class='opacity-[0.75]' src='".$featured_item['thumbnail']."' alt='".strtolower($featured_item['name'])."'>
</div>
<img class='opacity-[0.75]' src='".$featured_item['thumbnail']."' alt='".strtolower($featured_item['name'])."'>
</div>
";
";
}
$counter++;
if ($counter >= 2) {
break;
}
}
}
?>