Why does this select not work?

Hey,

I don’t understand why this SELECT does not work. It is basically retrieving events from a table where the date is more than or equal to the current date. Now if i add an event with the date of March it brings up the event. See this page:

http://www.glofamily.com/inner/index.php

However when i add an event for April, May etc… It doesn’t return anything…

This is the code:


    public function selectNextOnStage(){
        $sql = "SELECT *
                FROM c2_innerglo.tbl_events e
                WHERE DAY(date) >= DAY(CURRENT_DATE)
                AND archive = 0 AND deleted = 0
                ORDER BY date ASC
                LIMIT 1";
        $result = mysql_query($sql) or die($sql);
        if(!$result)
                print mysql_error(); 
        return $result;
    } 

Then i call the function like so:


			        $event = Event::selectNextOnStage();
			        $i = 0;
			        while($row = mysql_fetch_array($event)){
}
			        ?>

Any ideas what i’m doing wrong?

Thanks

DAY() returns the day of month (i.e. for March 25th, 25). The day of month for April 1st is 1, which is not greater than 25.

Just compare the dates directly

SELECT * 
FROM 
  c2_innerglo.tbl_events e 
WHERE 
  date >= CURRENT_DATE
AND archive = 0 AND deleted = 0 
ORDER BY 
  date ASC 
LIMIT
  1

Perfect.

That worked for me :slight_smile:

Thanks again