Hi
i am trying to assign values for room 1
//$Child1 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST-AGE'];
//$Child2 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@1-AGE'];
//$Child3 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@2-AGE'];
//$Child4 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@3-AGE'];
//$Child5 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@4-AGE'];
and room 2
//$R2Child1 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST-AGE'];
//$R2Child2 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@1-AGE'];
//$R2Child3 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@2-AGE'];
//$R2Child4 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@3-AGE'];
//$R2Child5 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@4-AGE'];
but the problem is if there is less than 5 children then in room 2
the GUEST@ changes in room 2 for example if 2 children in room 1
the 1st child in room 2 will become $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@2-AGE'];
which I want to become
//$R2Child1 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@2-AGE'];
//$R2Child2 = $result['RATES/OCCUPANTDETAILS/CHILDREN/GUEST@3-AGE'];
etc....
I have tried but know it is not correct
// loop and display all guest-age room1
$child = array();
$ii = 1;
$q = "";
while(1)
{
if ($ii) $q = "@".$ii;
$m = "RATES/OCCUPANTDETAILS/CHILDREN/GUEST".$q."-AGE";
if (!isset($result[$m])) break;
$child[] = $result[$m];
"$Child".$ii = $result[$m];
print "$Child".$ii;
$ii++;
}
}//
// loop and display all guest-age room2
$child = array();
$ii = 1;
$q = ""; /need to assign next $q from room1
while(1)
{
if ($ii) $q = "@".$ii;
$m = "RATES/OCCUPANTDETAILS/CHILDREN/GUEST".$q."-AGE";
if (!isset($result[$m])) break;
$child[] = $result[$m];
"$Child".$ii = $result[$m];
print "$Child".$ii;
$ii++;
}
but am unable to assign values as i wish
The first loop in room 1 will show the last "$Child".$ii; value
but that is not what i am trying to achieve
Hope you can make sense of this and look forward to your assistance
Regards
Ron
FULL CODE BELOW
{code saved}
Hello Ron,
A slightly different pattern would probably be more appropriate here, by looping each entry in $record, testing for RATES@n-ROOM and setting a room number variable; used as the index into the $child array. Have a go with something like:
$child = array();
$currentRoom = "";
foreach($result as $key => $value)
{
if ( (strpos($key,"RATES")!==FALSE) && (strpos($key,"ROOM")!==FALSE) )
{
$currentRoom = $value;
$child[$currentRoom] = array();
continue;
}
if ( (strpos($key,"CHILDREN")!==FALSE) && (strpos($key,"AGE")!==FALSE) )
{
$child[$currentRoom][] = $value;
continue;
}
}
print_r($child)
The output of print_r() will be something similar to:
Array
(
[1] => Array
(
[0] => 5
[1] => 7
[2] => 9
)
[2] => Array
(
[0] => 2
[1] => 9
)
)
...giving you a multi-dimensional array, primary index being the room number, each entry being a single dimensional array of each child's age.
Hope this helps!
Cheers,
David
--
MagicParser.com