jvance38 Posted September 9, 2011 Share Posted September 9, 2011 I have a mysql database where users enter their data using a form that includes a rundate input field that generates a calendar date in this type of format: xx/xx/xxxx into a mysql database field called rundate. I would like to query the database to search a string of dates that are in the database, such as 01/01/2011, 01/02/2011, 01/03/2011 but I'm not sure on how to code this into my search.php. I have attached the search page to this post. Any suggestions would be greatly appreciate, and if you need me to be more expanded on my explanation, just let me know....i try to keep it very simplistic. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/246803-query-a-string-of-dates-selected-from-a-datepicker-calendar/ Share on other sites More sharing options...
voip03 Posted September 9, 2011 Share Posted September 9, 2011 Please post the code. Quote Link to comment https://forums.phpfreaks.com/topic/246803-query-a-string-of-dates-selected-from-a-datepicker-calendar/#findComment-1267460 Share on other sites More sharing options...
jvance38 Posted September 12, 2011 Author Share Posted September 12, 2011 I attached the actual php search page to my initial post Quote Link to comment https://forums.phpfreaks.com/topic/246803-query-a-string-of-dates-selected-from-a-datepicker-calendar/#findComment-1268363 Share on other sites More sharing options...
AbraCadaver Posted September 12, 2011 Share Posted September 12, 2011 Well, you need to post the code as most people don't want to open attachments. Since I answered this elsewhere I will post it. This is an example: $dates = "'" . implode("','", array_map('mysql_real_escape_string', explode(',', $_POST['rundate']))) . "'"; $query_getRundate = sprintf("SELECT * FROM daily_budget WHERE rundate IN (%s)", $dates); In short, you need to explode the comma separated list into an array and then join it back into a comma separated list with quotes around each date, then use it in the WHERE IN () clause. I added mysql_real_escape_string() for safety. Quote Link to comment https://forums.phpfreaks.com/topic/246803-query-a-string-of-dates-selected-from-a-datepicker-calendar/#findComment-1268389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.