Retrieving a week number - Help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shuffweb
Forum Newbie
Posts: 5
Joined: Fri Apr 11, 2008 11:28 am

Retrieving a week number - Help needed

Post by shuffweb »

Hi everyone, im after a bit of help on the simplest of PHP/MySQL problems.

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");
}
}
 
 
 
 
?>
 
Problem : There are no errors on the page, however according to the table the week number should be 28 yet the week number that the query retrieves is always week number 26. Im not sure what to do??

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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Retrieving a week number - Help needed

Post by pickle »

Look up date() & the 'W' parameter.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply