Jump to content

Send value trough loops


Roy Barten

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.