I have a expenses script that displays the current week by week number based on week number in the database (w10) and can select other weeks by using ?selectWeek=w46
We have been using this script for a year now and does not show the information for this week (w10) because there are 2 entries in the database for w10 and it's getting confused which one to display.
Database Structure
ID - Base_Charge - Week - Year - Created_ At
1 - 20000 - w10 - 2021 - 2021-03-08
53 - 454333 - w10 - 2022 - 2022-03-07
Code:
<?php
include '../main.php';
check_loggedin($pdo);
// output message (errors, etc)
$msg = '';
$stmt = $pdo->prepare('SELECT * FROM expense_base_charge');
$stmt->execute();
$weekList = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(isset($_GET['selectWeek'])){
$week = $_GET['selectWeek'];
}else{
$ddate = date('y-m-d');
$date = new DateTime($ddate);
$week = 'w'.$date->format("W");
}
$stmt = $pdo->prepare('SELECT * FROM expense_base_charge where week = ?');
$stmt->execute([$week]);
$base_charge = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $pdo->prepare('SELECT * FROM expense where week = ?');
$stmt->execute([$base_charge['id']]);
$expense = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Any idea how to make it view the correct week please?