josephman1988 Posted November 24, 2010 Share Posted November 24, 2010 Hi guys, Need some help with arrays! The following code puts ALL dates into an array, or should I say should. Because this: do { $start = $row_getCalendarDates['page_date']; $end = $row_getCalendarDates['page_date02']; $init_date = strtotime($start); $dst_date = strtotime($end); $offset = $dst_date-$init_date; $dates = floor($offset/60/60/24) + 1; $booked=0; while ($booked < $dates) { $newDateFinal[] = date("Y-m-d", mktime(12,0,0,date("m", strtotime($start)), (date("d", strtotime($start)) + $booked), date("Y", strtotime($start)))); $booked++; } print_r($newDateFinal); } while ($row_getCalendarDates = mysql_fetch_assoc($getCalendarDates)); Infact prints something like so when i have multiple results: Array ( [0] => 2010-12-01 [1] => 2010-12-02 [2] => 2010-12-03 ) Array ( [0] => 2010-12-01 [1] => 2010-12-02 [2] => 2010-12-03 [3] => 2010-11-01 [4] => 2010-11-02 [5] => 2010-11-03 [6] => 2010-11-04 [7] => 2010-11-05 [8] => 2010-11-06 [9] => 2010-11-07 [10] => 2010-11-08 ) These are 2 results coming from the database, so what it is doing is putting both into arrays, but I 'NEED' them iin a single array, how on earth do I go about doing this? Note however, how the first array has the first set of results but the second has them all ... this is affecting my code and so, need to somehow reference and get rid of the first array. Hope someone can help! Regards, Joe. Quote Link to comment https://forums.phpfreaks.com/topic/219682-array-trouble-within-a-while-loop/ Share on other sites More sharing options...
kenrbnsn Posted November 24, 2010 Share Posted November 24, 2010 Move the print_r outside your "while" loop. Ken Quote Link to comment https://forums.phpfreaks.com/topic/219682-array-trouble-within-a-while-loop/#findComment-1138925 Share on other sites More sharing options...
ManiacDan Posted November 24, 2010 Share Posted November 24, 2010 Or do like you were told on devshed and remove this loop entirely. Quote Link to comment https://forums.phpfreaks.com/topic/219682-array-trouble-within-a-while-loop/#findComment-1138929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.