Scenario: I am creating a get_week_number() function which established the current date and stores the value in the $_SESSION['current_date'] variable,
I then initiate a query which compares this value to the start_date and end_date fields in a table named 'week' to establish the current week number.
Code: Select all
<?php
session_start();
require_once ('./includes/db_connect.php');
$current_date = date("Y-m-d");
$_SESSION['current_date'] = $current_date;
if (isset($_SESSION['current_date'])){
$query =
"SELECT week.week_id
FROM week
WHERE '{$_SESSION['current_date']}' >= week.start_date
AND < week.end_date
";
$result = mysql_query($query);
// Return a record, if applicable.
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row)
{
$_SESSION['week_number'] = $row[0];
echo ("The week_number is " .$_SESSION['week_number']);
}
else{
echo ("The Week is $current_date");
}
}
?>
Any help would be highly appreciated,
and feel free to give me a clip round the ear, for missing something that I can imagine is going to be easy to solve.