Scorpion Posted February 9, 2011 Posted February 9, 2011 Right i'm building a site that will have a deals page and in the table i have id, Title, Start_date, End_date,Important, Information, Full_information, Price, Image(<-- a link to where the picture is) well i need to make sure that the deals are only there between two dates so i did a query below and thought that looks like it works but nope and there is data in the table 1 One Deal 2011-02-01 2011-02-23 Just some info More info £20.50 .jpg SELECT id, Title, Start_date, End_date,Important, Information, Full_information, Price, Image FROM web_Deals WHERE Start_date <= '.date("Y-m-d").' AND End_date >= '.date("Y-m-d") I'm using php so thats where .date("Y-m-d") is coming from and yes the date on the server is correct. Hopefully its something simple if there isn't a way to do it this way but another way i will be happy to learn. Quote
Jason Cooper Posted February 9, 2011 Posted February 9, 2011 The logic looks correct, do you get any errors? Does it need a semicolon ';' on the end of the line, sometimes languages require that other times they don't depends on the database, language and how they are connected. If you don't get any errors then try outputting the SQL that is generated and putting it manually into mysql, it usually will help you figure out what is wrong. Quote
Scorpion Posted February 9, 2011 Author Posted February 9, 2011 I've tried it in phpmyadmin with dates and it brings up zero results so there is no errors its just odd, by the way the Start_date and End_date are set to Date do you think that could be a problem? Quote
Jason Cooper Posted February 9, 2011 Posted February 9, 2011 assuming date("Y-m-d") is generating the current date then try this SQL instead which uses MySQL's NOW() function. SELECT id, Title, Start_date, End_date,Important, Information, Full_information, Price, Image FROM web_deals WHERE Start_date <= NOW() AND End_date >= NOW(); Quote
Scorpion Posted February 9, 2011 Author Posted February 9, 2011 Thats it, it worked i wonder why it wanted that instead but thank you for helping me out i thought the query wasn't wrong (in away). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.