retrieving multiple dates from mysql database
Posted: Mon Sep 12, 2011 10:05 am
I hope someone can point me in the right direction. I have a form that has an input field called "rundate" which is populated with a jquery multiSelect Calendar that allows a user to select up to 6 dates to query. My database contains a "rundate" column that contains dates entered in this type of format 01/01/2011. I am trying to utilize the multiselect calendar to query the database for any dates in the database that match the selected dates from the form which are seperated by a "," like so 01/01/2011, 01/02/2011, 01/03/2011 etc. My form at the moment only will return results if the rundate only contains one selected date, but when i select more than one date, i don't get any results returned. Does anyone know what I can do to retrieve all the results in the database that match the dates selected from the form? I'm thinking that the comma seperating the dates may be the problem but, I'm hoping for some guidance. Thanks in advance.
Code: Select all
<?php require_once('../Connections/connAdmin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$colname_getRundate = "-1";
if (isset($_POST['rundate'])) {
$colname_getRundate = $_POST['rundate'];
}
mysql_select_db($database_connAdmin, $connAdmin);
$query_getRundate = sprintf("SELECT * FROM daily_budget WHERE rundate LIKE %s", GetSQLValueString("%" . $colname_getRundate . "%", "text"));
$getRundate = mysql_query($query_getRundate, $connAdmin) or die(mysql_error());
$row_getRundate = mysql_fetch_assoc($getRundate);
$totalRows_getRundate = mysql_num_rows($getRundate);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/new_budget/advanced_budgeting/jquery.min.js"></script>
<style type="text/css">
@import "/new_budget/advanced_budgeting/flora.datepick.css";.mainNav {
font-size: 20px;
font-weight: bold;
background-color: #FFF;
}
</style>
<script type="text/javascript" src="/new_budget/advanced_budgeting/jquery.datepick.min.js"></script>
</head>
<body><form action="" method="get" name="rundate">
<label for="rundate">Rundate:</label>
<input type="text" name="rundate" size="30" value="" id="multi999Picker"/>
</p>
<script type="text/javascript">
// BeginWebWidget jQuery_UI_Calendar: range2Picker
$('#multi999Picker').datepick({
multiSelect: 6, multiSeperator: ',', monthsToShow: 2,
showTrigger: '#calImg'});
// EndWebWidget jQuery_UI_Calendar: range2Picker
</script>
<input type="submit" align="middle" name="search" id="search" value="Search" />
</form>
<table id="results" width="100%" align="left" bgcolor="#FFFFFF">
<?php do { ?>
<tr>
<td><p><?php echo $row_getRundate['rundate']; ?>
<p><?php echo $row_getRundate['slug']; ?>
<p><?php echo $row_getRundate['reporter']; ?>
<p><?php echo $row_getRundate['budgetInfo']; ?><br/>
<hr />
<?php } while ($row_getRundate = mysql_fetch_assoc($getRundate)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($getRundate);
?>