Jump to content

Finding records by date using a drop down menu


sivarts

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.