Problems with if.... loop inside foreach loop
Posted: Sat Nov 28, 2009 7:37 am
Basically, the user chooses an option and the matching links are shown. But as soon as the page loads, ALL the links are listed. How can I stop the links appearing before the selection ????
What's happeneing it that a text file containing hotel details is opened. The first 7 entries aren't needed so I sliced them off. The remaining details are names of function room, each of which has its own text file of details. I want to display a series of links based on the Size of each room.
http://dunluce.infc.ulst.ac.uk/ac08tb/c ... 4/test.php
Here's a link to the actual webpage
Code: Select all
<div class="box">
<form action="test.php" method="post">
Number of Guests: <br/>
<input type="radio" name="guests" value="50" /> 0 - 50 .
<input type="radio" name="guests" value="100" />51 - 100 .
<input type="radio" name="guests" value="150" />101 - 150 .
<input type="radio" name="guests" value="151" />151 + . <br/>
<input type="submit" value="Submit"/>
</form>
<?php
$x = $_POST['guests'];
foreach($pleaseGod as $list=>$hotel)
{
$rooms = array_slice($hotel,7);
foreach($rooms as $room)
{
if ( $x <= $room['Size'] )
{?>
<a href="chosenRoom.php?hotel=<?php echo $list ?>&room=<?php echo $room['Name'] ?>">
<?php echo $room['Name'] ?>
</a> <br/> <?php
}
}
}
?>
</div>
What's happeneing it that a text file containing hotel details is opened. The first 7 entries aren't needed so I sliced them off. The remaining details are names of function room, each of which has its own text file of details. I want to display a series of links based on the Size of each room.
http://dunluce.infc.ulst.ac.uk/ac08tb/c ... 4/test.php
Here's a link to the actual webpage