Jump to content

SQL Filter >= and <= information needed


ded

Recommended Posts

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

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

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

  • 1 month later...

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.