1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-20 01:09:35 +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

@@ -15,13 +15,19 @@
</div> </div>
<div class="w-[50%] lg:w-[25%] flex flex-col justify-start items-start mb-10 lg:mb-0"> <div class="w-[50%] lg:w-[25%] flex flex-col justify-start items-start mb-10 lg:mb-0">
<h6 class="font-bold mb-8">Featured</h6> <h6 class="font-bold mb-8">Featured</h6>
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured Project 1</a> <?php
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured 2</a>
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured Content 3</a> $featured_projects_footer = fetch_featured_projects($conn);
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured Project</a>
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured Project</a> if($featured_projects_footer -> num_rows > 0) {
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured Content 6</a> while($featured_footer_item = $featured_projects_footer -> fetch_assoc()) {
<a class="text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100" href="">Featured 7</a> echo "
<a class='text-sm text-accent_three my-1 hover:text-accent_secondary transition transform duration-100' href='".$featured_footer_item['link']."' target='_blank'>".$featured_footer_item['name']."</a>
";
}
}
?>
</div> </div>
<div class="w-[50%] lg:w-[25%] flex flex-col justify-start items-start mb-10 lg:mb-0"> <div class="w-[50%] lg:w-[25%] flex flex-col justify-start items-start mb-10 lg:mb-0">
<h6 class="font-bold mb-8">Follow Me On</h6> <h6 class="font-bold mb-8">Follow Me On</h6>

View File

@@ -1,3 +1,8 @@
<?php
require './core/connection.php';
require './core/query_functions.php';
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>

View File

@@ -1,3 +1,8 @@
<?php
require './core/connection.php';
require './core/query_functions.php';
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>

View File

@@ -0,0 +1,31 @@
<?php
//function to create an array of all unique project years
function create_project_years_array($conn) {
$sql = "SELECT DISTINCT year FROM projects ORDER BY year DESC";
$result = $conn -> query($sql);
if ($result) {
$years = array();
while ($row = $result -> fetch_assoc()) {
$years[] = $row['year'];
}
return $years;
}
}
//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($conn) {
$sql = "SELECT * FROM featured_projects";
$result = $conn -> query($sql);
return $result;
}
?>

View File

@@ -1,3 +1,8 @@
<?php
require './core/connection.php';
require './core/query_functions.php';
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>

View File

@@ -1,32 +1,8 @@
<?php <?php
require './core/connection.php'; require './core/connection.php';
require './core/query_functions.php';
$sql = "SELECT DISTINCT year FROM projects ORDER BY year DESC"; $years = create_project_years_array($conn);
$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;
}
?> ?>
<!DOCTYPE html> <!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"> <div class="w-full flex flex-col justify-center items-center mb-12">
<?php <?php
$featured_projects = fetch_featured_projects_sidebar($conn); $featured_projects = fetch_featured_projects($conn);
if($featured_projects -> num_rows > 0){ if($featured_projects -> num_rows > 0){
//show top 2 featured projects for sidebar
$counter = 0;
while($featured_item = $featured_projects -> fetch_assoc()) { while($featured_item = $featured_projects -> fetch_assoc()) {
echo " if ($counter < 2) {
<div class='group w-[250px] rounded-lg overflow-hidden my-3 relative border-accent_three hover:border-[3px] transition-[border-width] transform duration-100'> echo "
<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'> <div class='group w-[250px] rounded-lg overflow-hidden my-3 relative border-accent_three hover:border-[3px] transition-[border-width] transform duration-100'>
<h6 class='text-xl mb-1'>".$featured_item['name']."</h6> <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'>
<p class='text-xs font-[300] mb-4 text-accent_three'>".$featured_item['description']."</p> <h6 class='text-xl mb-1'>".$featured_item['name']."</h6>
<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> <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> </div>
<img class='opacity-[0.75]' src='".$featured_item['thumbnail']."' alt='".strtolower($featured_item['name'])."'> ";
</div> }
"; $counter++;
if ($counter >= 2) {
break;
}
} }
} }
?> ?>