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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

  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.

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