Roy Barten Posted February 17, 2009 Share Posted February 17, 2009 Hello, now i wrote the following code: <? function calendarShowReservations($calendartype) { if ($calendartype == "week"){//als het type week is $countres = 0;//aantal reserveringen = 0 for($i = 0; $i <= 23; $i++)//de waardes van de kalenderopbouw gebruiken { $startnumber = $i;//starnummer onthouden LookForReservation($calendartype,$startnumber);//kijken voor reserveringen } } if ($calendartype == "month"){ for($i = 0; $i <= 6; $i++)//de waardes van de kalenderopbouw gebruiken { echo "<tr height=20><td>".$i.":00"."</td rowspan=$countrows><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; $number = $i; LookForReservation($calendartype); } } } function ConvertToDateTime($number,$calendartype) { if ($calendartype == "week"){ $time = date("$number:00:00 2009-03-02"); $date = strtotime($time); } if ($calendartype == "month"){ $day = date("00:00:00 2009-03-$number"); $date = strtotime($day); } return $date; } function LookForReservation($calendartype,$startnumber)//kalendertype en startnummer worden meegegeven { include ("array.php");//array openen foreach($array as $val)//array aflopen { $number = $startnumber; //number = startnumber $s_date = strtotime($val['start']);//startdatum in gevonden array converteren naar date $e_date = strtotime($val['end']); $date = ConvertToDateTime($number,$calendartype);//gekozen datum converteren naar date, uitkomst is $date if($date > $s_date && $date < $e_date) //als de gekozen datum tussen de start en enddate ligt { $day = $startnumber + 1; //1 waarde optellen bij het startnummer. $date = ConvertToDateTime($day,$calendartype);//deze opgetelde waarde in $date zetten $countres++;//de reserveringsteller optellen $id = $val['id'];//reserveringsid ophalen DisplayDurationReservation($id,$calendartype,$s_date,$e_date,$date,$val['id']);//vervolgens de display regelen } } } function DisplayDurationReservation($id,$calendartype,$s_date,$e_date,$date,$val) { while($date > $s_date && $date < $e_date && $id == $val['id'])//zolang de datum er nog steeds tussenin valt { if ($calendartype == "week"){//kalendertype bekijken $day = $day + 1;//een uurtje optellen bij de datun ($date) voor de volgende test in de loop $date = ConvertToDateTime($day,$calendartype); $countrows++;//de urenteller optellen return $countrows; } if ($calendartype == "month"){ $day++; ConvertToDateTime($number, $calendartype); $countdays++; } //$counthours is nu het aantal uren, of het aantal rijen dat samengevoegd moet worden. } } ?> I want the value from $countrows into the first loop. You can find $countrows into the function DisplayDurationReservation. With the first loop I mean the loop in the function CalendarShowReservations how do i do this? Quote Link to comment https://forums.phpfreaks.com/topic/145568-send-value-trough-loops/ Share on other sites More sharing options...
rameshfaj Posted February 17, 2009 Share Posted February 17, 2009 You are initialzing some variable inside one method and want to have the variable's value in another method ,in that case you need to call the method(where the variable is to be used) from the point where the variable is initialized. OR make sure that the variable's value is stored some where such that the other method finds it.This can be achieved using global variables and calling the methods in proper order. Quote Link to comment https://forums.phpfreaks.com/topic/145568-send-value-trough-loops/#findComment-764285 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.