This seems like a strange problem to me, but PHP seems incapable of using a variable passed from the query string when constructing a for loop.
As far as i’m aware there’s no parsing required, and data coming from the query string should be…a string anyway.
Despite the fact I can print out the values once i’ve retrieved them from the query string, this does not work:
$from = $_GET['dealfrom'];
$to = $_GET['dealto'];
$fromDate = $from;
$toDate = $to;
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
// use date() and $currentDateTS to format the dates in between
$currentDateStr = date("Y-m-d",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
//print $currentDateStr.”<br />”;
}
echo "<pre>";
print_r($dateMonthYearArr);
echo "</pre>";
If I set the values explicitly to strings ($fromdate and $todate) to exactly what i’m passing in the query string, then the code runs perfectly.
Is this a limitation of PHP in some way, or am I just missing something really obvious? Been banging my head on the wall over this one.
Your code worked fine for me using $_GET. Like others, I believe that it is the formatting issue of the string you’re getting from the $_GET param.
I tested it with these values: 01/20/2011 – 03/30/2011 and I got the array to print out.
Make sure you clearly analyze what the $_GET param contains and strtotime() will hopefully oblige.