Problems with if.... loop inside foreach loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rumblefish1976
Forum Newbie
Posts: 5
Joined: Mon Nov 23, 2009 4:22 am

Problems with if.... loop inside foreach loop

Post by rumblefish1976 »

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 ????

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
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Problems with if.... loop inside foreach loop

Post by daedalus__ »

i dont understand.

check for a request variable then list entries starting with that number + 50?

Code: Select all

 
if (is_null($_GET['start']))
{
    $s = 0;
}
else
{
    $s = $_GET['start'];
}
 
for ($i = $_GET['start']; $i <= 50; $i++)
{
   list_links();
}
 
Post Reply