SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sql Select code not working

    Hi Guys

    I am trying to select mysql data that is between two days in the past to 3 days in the future but I am having issue even to get any output from the codes I have found this is what I have so far it still doesn't work

    $result = mysqli_query($con,"SELECT * FROM Despatch WHERE Branch = 'B' AND Despatch_Date BETWEEN NOW() and NOW(), INTERVAL 7 DAY ORDER BY Despatch_Date ASC");

    Any help would be great I have been trying to work out how to do it for afew days now

  2. #2
    SitePoint Zealot Sogo7's Avatar
    Join Date
    May 2011
    Posts
    129
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Lateral Logic...
    Add 3 days to the current time then you look backwards through the table over seven days

    DATE_SUB(DATE_ADD(CURDATE,INTERVAL 3 DAY)),INTERVAL 7 DAY) > ORDER BY Despatch_Date ASC

    looks about right but I'm still on the first coffee of the morning
    Lovelogic.net Personal Projects Pit - Spammers welcome

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Thanks for the help am new to the mysql so its a little confusing so I need to put my code like this I been looking online but can't seem to get my head around it

    $result = mysqli_query($con,"SELECT * FROM Despatch,DATE_SUB(DATE_ADD(CURDATE,INTERVAL 3 DAY)),INTERVAL 7 DAY) > ORDER BY Despatch_Date ASC AND WHERE Branch = 'B' ");


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
  •