Note that there are some explanatory texts on larger screens.

plurals
  1. POWhile loop making too many arrays
    text
    copied!<p>I need help, badly. What I am making right now is a date picker. Pretty much updating on it for my own use.</p> <p>I needed to block out specific date ranges. I found a code to do this, and it utilizes arrays. I like that.</p> <p>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.</p> <p>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. Essentially, what I need is just 1 array.</p> <p>I've tried a few things, but nothing seems to work. Been thinking about this for a while now. Any help? <code></p> <pre><code>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 &gt;= $iDateFrom) { array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry while ($iDateFrom&lt;$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 "&lt;br /&gt;"; } } </code></pre> <p></code><br> And for those wondering, I do include references of where some of my work is taken from, even if heavily modified.</p> <p>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).</p> <p>So, what can I do here?</p> <p>What I always get back is (I only have 2 rows of dummy data): </p> <p><code> 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 )<br> Array ( [0] => 2010-12-25 [1] => 2010-12-26 [2] => 2010-12-27 [3] => 2010-12-28 [4] => 2010-12-29 ) </code> </p> <p>The problem lies with the loop itself. The first instance does what it is tole to do. The second instance onwards, $aryDates just gets replaced.</p> <p>Any help would be greatly appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload