Jump to content

query a string of dates selected from a datepicker calendar


jvance38

Recommended Posts

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]

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.

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.