Jump to content


Photo

Finding records by date using a drop down menu


  • Please log in to reply
4 replies to this topic

#1 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 09 August 2006 - 09:12 PM

HI-

I am trying to let users search for events by date. I have a drop down menu with the following:
Today
This Week
Next Week
This Month

What I want to do is set up If/else statements that would take one of the above (passed as $_GET['searchDate']) and and perform a SQL query based on the variable (Today, This Week, etc.). I need to know how to structure the if/else statement and also how to code the PHP so that it knows that This Week is today plus the next 6 days and so forth. I have set up something like :

$query = $_GET['searchDate'];

if ($query = 'Today') { //get recordset for today
}
elseif ($query = 'This Week') { //get recordset for This week
}
and so on...It doesn't seem to work though (I  have not actually set up any SQL queries yet, but I have set it to display the value of $query for testing. It only gives me the first if clause (today). I am a PHP newbie, so I know I am missing something obvious but can't seem to find the answer.

Can anyone provide me with help? Is this the best way to do this or is there a better way to look up records based on the date? I would also like to provide a calendar on the page that they could click a date and it would show the records listed for that date. I have been looking around the web and I cannot find an example of this, but I know some one has done something like this somewhere.

Any help would be appreciated.Thanks

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 09 August 2006 - 09:14 PM

How are you storing dates in your db?
PHP Ninja

#3 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 09 August 2006 - 11:01 PM

I am storing them in SQL format (yyyy-mm-dd). I would also like to know if there is a good way to have people enter dates in a more human readable format and have them converted to SQL format. Right now, when enetering dates people have to enter them in the SQL format which is a bit of an usability issue.

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 09 August 2006 - 11:05 PM

You should store them as timestamps. That way, you can easily convert the dates for display purposes, while using the dates in many other ways, without much effort or formatting. You should only format the timestamps/dates for display purposes.
PHP Ninja

#5 sivarts

sivarts
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 10 August 2006 - 02:32 AM

Caesar - thanks for the advice. In the future I definately will use timestamps. I should have thought of that a month ago...but at this point the clients are already using the db the way it is. Plus, I have a very limited timefrmae to get the project finished (one week!!). I wouldn't have time to change all the dates in the db and rework my php scripts to work with those changes...I'll keep working on it and see what I come up with.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users