Jump to content

Mysql Problem


Scorpion
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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.

 Share

  • Recently Browsing   0 members

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