ded Posted March 2, 2008 Share Posted March 2, 2008 Good Morning All, I have a sdate field and an edate field within a table and want to be able to filter by a certain month the user selects. I do not have a month field. I was thinking to do a >= and <= in the URL to filter. How woule that be set up? Am I going in the right direction? function monthHandler(form){ $month = $_GET['month']; if ($month == '1'){ $start = 20080101; $end = 20080201; } if ($month == '2'){ $start = 20080201; $end = 20080301; } ........... formula = "sdate>= . begin . && . edate< . end" var URL = "http://www.website.com/index.php?"+formula; window.location.href = URL; } Thanks, DED Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/ Share on other sites More sharing options...
QuietWhistler Posted March 2, 2008 Share Posted March 2, 2008 $sql = "SELECT * FROM `table` WHERE `sdate` > '" . $_GET[ "begin" ] . "' && `edate` < '" . $_GET[ "edate" ] . "'"; mysql_query( $sql ); That should do it. Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-481598 Share on other sites More sharing options...
ded Posted March 2, 2008 Author Share Posted March 2, 2008 I changed the script around a bit.....something is wrong with the URL that is posted. It still brings up everything. http://www.website.com/index.php?sdate>=20080601&&edate<20080701 Shouldn't the above just bring up June? <form name="month"> <select name="site" size="1" onchange="javascript:monthHandler()"> <option value="">By Month</option> <option value="ALL">Full Year</option> <option value="20080101">January 08</option> <option value="20080201">February 08</option> <option value="20080301">March 08</option> <option value="20080401">April 08</option> <option value="20080501">May 08</option> <option value="20080601">June 08</option> <option value="20080701">July 08</option> <option value="20080801">August 08</option> <option value="20080901">September 08</option> <option value="20081001">October 08</option> <option value="20081101">November 08</option> <option value="20081201">December 08</option> </select> </form> function monthHandler(form){ var end = month.site.value + 100; var URL = "http://www.website.com/index.php?sdate>="+month.site.value+"&&edate<"+end; window.location.href = URL; } $monthk = $_GET['month']; $sdatek = $monthk; $edatek = $monthk + 100; $queryt = "SELECT * FROM `table` WHERE `sdate` >= '$sdatek' and `edate` < '$edatek' ORDER BY `sdate`"; $resultt = mysql_query($queryt,$dbh) or die(mysql_error()); Thanks, DED Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-481601 Share on other sites More sharing options...
QuietWhistler Posted March 2, 2008 Share Posted March 2, 2008 You can't use comparison operators in an URL. Just assign the variables like: http://www.website.com/index.php?sdate=20080601&&edate=20080701 and then use that query. Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-481609 Share on other sites More sharing options...
ded Posted March 2, 2008 Author Share Posted March 2, 2008 QW, Thank you for the help. Still not working as I wish. The problem may be the 100 is actually concatenating instead of adding. example month.site.value = 20080101 var end = month.site.value + 100; end becomes 20080101100 instead of 20080201 The URL is currently coming out as http://www.website.com/index.php?sdate=20080101&&edate=20080101100 and the entire calendar list is showing instead of just the month selected. Could this be the problem? How do I make this numeric and add instead of cat? That may be the problem. Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-481624 Share on other sites More sharing options...
ded Posted April 4, 2008 Author Share Posted April 4, 2008 Friendly Bump Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-509617 Share on other sites More sharing options...
benjaminbeazy Posted April 5, 2008 Share Posted April 5, 2008 try this... var end = int(month.site.value) + 100; Link to comment https://forums.phpfreaks.com/topic/94000-sql-filter-and/#findComment-509821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.