How to pull date specific data from mysql database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ted Cumpston
    New Member
    • Jan 2011
    • 3

    #1

    How to pull date specific data from mysql database?

    Hi all.

    I'm a complete newbie to PHP and could use some help in figuring this out. I have a php page that pulls it's content from a database. I'm able to display this without a problem. I would like to have the content be able to change depending on the date.

    My database is called mobilesites. The table I'm extracting the data from is called promos. The fields are promoID, startDate, endDate, promoLocation (location of the picture), promoHeader (H1 content) and promoDetails (descriptive content). There is only one promo active at a time. Can anyone point me in the right direction please?
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    If you would like to see promos that should be active today meaning:

    today is greater or equal to startDate also today is less than or equal to the endDate.

    Just convert the above to SQL:
    Code:
    SELECT * FROM promos WHERE startDate <= NOW() AND endDate >= NOW();
    That will work if startDate and endDate are DATETIME columns and not just a CHAR or VARCHAR.

    By the way, this is a Database query question rather than a PHP question.

    Cheers,

    Dan

    Comment

    • Ted Cumpston
      New Member
      • Jan 2011
      • 3

      #3
      Okay, so I have the query set, how do I display this on a php page?

      Comment

      • Ted Cumpston
        New Member
        • Jan 2011
        • 3

        #4
        I have it working, thanks for your help.

        Comment

        Working...