SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP 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:

    PHP Code:
                        $event Event::selectNextOnStage();
                        
    $i 0;
                        while(
    $row mysql_fetch_array($event)){
    }
                        
    ?> 
    Any ideas what i'm doing wrong?

    Thanks
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

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

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect.

    That worked for me

    Thanks again
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •