sivarts Posted August 9, 2006 Share Posted August 9, 2006 HI-I am trying to let users search for events by date. I have a drop down menu with the following:TodayThis WeekNext WeekThis MonthWhat 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 https://forums.phpfreaks.com/topic/17066-finding-records-by-date-using-a-drop-down-menu/ Share on other sites More sharing options...
Caesar Posted August 9, 2006 Share Posted August 9, 2006 How are you storing dates in your db? Link to comment https://forums.phpfreaks.com/topic/17066-finding-records-by-date-using-a-drop-down-menu/#findComment-72041 Share on other sites More sharing options...
sivarts Posted August 9, 2006 Author Share Posted August 9, 2006 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 https://forums.phpfreaks.com/topic/17066-finding-records-by-date-using-a-drop-down-menu/#findComment-72101 Share on other sites More sharing options...
Caesar Posted August 9, 2006 Share Posted August 9, 2006 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 https://forums.phpfreaks.com/topic/17066-finding-records-by-date-using-a-drop-down-menu/#findComment-72103 Share on other sites More sharing options...
sivarts Posted August 10, 2006 Author Share Posted August 10, 2006 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 https://forums.phpfreaks.com/topic/17066-finding-records-by-date-using-a-drop-down-menu/#findComment-72236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.