Jump to content

Recommended Posts

Posted

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 &lt;= '.date("Y-m-d").' AND End_date &gt;= '.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.

Posted

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.

Posted

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?

Posted

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 &lt;= NOW() AND End_date &gt;= NOW();

Posted

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).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...