|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a function which I am trying to incorporate into a MySQL query. I didn't write the function and I am only a newby at MySQL so I am totally lost. My question is how do I use the function below to allow the user to pick two dates which then are used to query the database for results between the two dates selected. Any and all suggestions are much appreciated! The function I am trying to use and the existing query into which I am trying to feed the selections are posted below. Thanks Again!
THE FUNCTION =================== <? function DateSelector($inName, $useDate=0) { /* create array so we can name months */ $monthName = array(1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); /* if date invalid or not supplied, use current time */ if($useDate == 0) { $useDate = Time(); } /* make month selector */ echo "<SELECT NAME=" . $inName . "Month>\n"; for($currentMonth = 1; $currentMonth <= 12; $currentMonth++) { echo "<OPTION VALUE=\""; echo intval($currentMonth); echo "\""; if(intval(date("m", $useDate))==$currentMonth) { echo " SELECTED"; } echo ">" . $monthName[$currentMonth] . "\n"; } echo "</SELECT>"; /* make day selector */ echo "<SELECT NAME=" . $inName . "Day>\n"; for($currentDay=1; $currentDay <= 31; $currentDay++) { echo "<OPTION VALUE=\"$currentDay\""; if(intval(date("d", $useDate))==$currentDay) { echo " SELECTED"; } echo ">$currentDay\n"; } echo "</SELECT>"; /* make year selector */ echo "<SELECT NAME=" . $inName . "Year>\n"; $startYear = date("Y", $useDate); for($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++) { echo "<OPTION VALUE=\"$currentYear\""; if(date("Y", $useDate)==$currentYear) { echo " SELECTED"; } echo ">$currentYear\n"; } echo "</SELECT>"; } ?> ============================= THE QUERY ============================= $result = mysql_query( "SELECT * FROM ttime where ((SNUM = '".$_SESSION['SNUM']."') and ".$TIDATE." like '%".$TIDATEA."%') or ((SNUM = '".$_SESSION['SNUM']."') and ".$TIDATE." like '%".$TIDATEB."%') ORDER BY TIDATE ASC") or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "You currently have $num_rows time entries for " ================================= |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Help with incorporating function into MySQL query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|