Welcome to WebmasterWorld Guest from 18.205.109.82

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP SQL date query

     
12:55 am on Jul 1, 2008 (gmt 0)

New User

10+ Year Member

joined:May 12, 2006
posts:21
votes: 0


Is it possible to somehow use php to change the number of the month in an sql query?

For example, if the user is on a page where the default month is 7 (this is my query: SELECT id, date FROM table WHERE month(date)='7')

and then he enters month 8 in a text box.. is it possible to place the 8 in the place of the 7 and then display the new results either on the same page or on a different page by clicking a button?

I assume that I need to store the value of the text box into a variable, which I'm thinking should go in the place of the 7. So, may be something like: SELECT id, date FROM table WHERE month(date)='varMonth'

However, I'm not sure how to go about the actual code.

5:43 am on July 1, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 16, 2007
posts:914
votes: 0


You'll take the value entered in the text box to put a new date back together. You'll also need the id you got from the select. Assuming you've got the date in $newdate and the id in $id:
mysql_query("UPDATE table SET date='$newdate' WHERE id=$id");
If id isn't numeric, surround it with single quotes the same way $newdate is.
4:43 pm on July 1, 2008 (gmt 0)

New User

10+ Year Member

joined:May 12, 2006
posts:21
votes: 0


I thought UPDATE was used to modify data in the table? What I was trying to do is just display a different set of data.. could you please clarify
5:54 pm on July 1, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 16, 2007
posts:914
votes: 0


I apologize for confusing you, as I was - I thought that's what you wanted to do. Yes, UPDATE is for modifying the table data. Your post is very nearly there, then, you just need a dollar sign:

SELECT id, date FROM table WHERE month(date)='$varMonth'

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members