SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    retrive record based on day of week

    Hello,

    I have a mySQL database setup that has the following fields.

    ID
    title
    desc
    price
    dayofweek

    I have config.php to connect to the db, etc. What I want to do is display the record associated with the day of the week.

    For instance, if it's Monday show data in reference to dayofweek=Monday. Tuesday, show Tues data.

    I know you can use curdate or timestamp but I'm not sure how to build my query for day of the week. Can it be done?

    I'm new to php and I'm not sure where to go. If someone could point me in the right direction I'd appreciate it.

  2. #2
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just read about the dayofweek function. If I use that to determine the day would I then use an if else if statement saying if dayofweek=1 show this ID and it's related fields etc.

  3. #3
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found something for anyone looking to do this:

    http://www.tutcity.com/view/changing...week.9919.html

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, you'd use a standard query which included your day as the where condition.

    SELECT ID, title, desc, price, dayofweek
    FROM yourTable
    WHERE dayofweek = $today

    (having previously said $today = date("l"); )

    Not an if..else in sight (or site)

  5. #5
    SitePoint Addict AtSea webdesign's Avatar
    Join Date
    May 2010
    Location
    Newark, Delaware
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Dr.John simple enough. I'll give it go.


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
  •