I need help, badly. What I am making right now is a date picker. Pretty much updating on it for my own use.
I needed to block out specific date ranges. I found a code to do this, and it utilizes arrays. I like that.
What I then needed was a way to create the array with every date within the range, because I only entered the Start Date and the End Date. Found one. Works like a charm.
But now, I have a problem. It creates a new array using the same $. So the only array that the calender registers is the newest one.
I've tried a few things, but nothing seems to work. Been thinking about this for a while now. Any help?
<?php
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createDateRangeArray($strDateFrom,$strDateTo) //Changes a Range of Dates to Specific Dates
{
$aryRange = array(); //Creates an Array
$iDateFrom = mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo = mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo >= $iDateFrom)
{
array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom += 86400; // add 24 hours
array_push($aryRange,date('Y-m-d',$iDateFrom));
}
}
return $aryRange; //Returns to step 1 and adds another value into the array
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$d = "SELECT startdate, enddate FROM classdetails";
$f = mysql_query($d);
while ($e = mysql_fetch_array($f))
{
while (list($g, $h) = each($e)) { $$g = $h; }
{
$aryDates = createDateRangeArray($startdate,$enddate);
print_r($aryDates);
echo "<br />";
}
}
?>
And for those wondering, I do include references of where some of my work is taken from, even if heavily modified.
As you can see, the problem lies with the fact that once it creates an array, it just creates a new one. I've tried using ifelse statements, empty(), isset(), increments (didn't even know how to use them, just thought a long time and deleted it).
So, what can I do here?
What I always get back is:
Array ( [0] => 2010-12-16 [1] => 2010-12-17 [2] => 2010-12-18 [3] => 2010-12-19 [4] => 2010-12-20 [5] => 2010-12-21 [6] => 2010-12-22 [7] => 2010-12-23 )
Array ( [0] => 2010-12-25 [1] => 2010-12-26 [2] => 2010-12-27 [3] => 2010-12-28 [4] => 2010-12-29 )
I can't even merge them.