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]

Link to comment
Share on other sites

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.

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.