Advertisement
Guest User

Untitled

a guest
Jan 27th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1.  $sql="SELECT Building, Room FROM Room WHERE Building = '".$building."'";
  2.  
  3.     $sqlresult = mysql_query($sql);
  4.  
  5.     $buildings = array(); // easier if you don't use generic names for data
  6.  
  7.     while($sqlrow = mysql_fetch_array($sqlresult))
  8.     {
  9.         // you need to initialise your building array cells
  10.         if (!isset($buildings[$sqlrow['Building']])) {
  11.             $buildings[$sqlrow['Building']] = array('Rooms' => array());
  12.         }
  13.  
  14.         // you can add the room to the building 'Rooms' array
  15.         $buildings[$sqlrow['Building']]['Rooms'][] = $sqlrow['Room'];
  16.     }
  17.  
  18.  
  19.     $buildingHTML = "";
  20.     $buildingHTML = "<form action=\"\" method=\"post\">";
  21.     $buildingHTML .= '<select name="buildings" id="buildingssDrop" onchange="document.getElementById(\'dropDownForm\').submit()">'.PHP_EOL;
  22.     $buildingHTML .= '<option value="">Please Select</option>'.PHP_EOL;
  23.  
  24.     foreach ($buildings as $building => $buildingData) {      
  25.         $buildingHTML .= "<option value='".$building."'>" . $building . "</option>".PHP_EOL;        
  26.     }
  27.     $buildingHTML .= '</select>';
  28.     $buildingHTML .= '</form>';
  29.  
  30.     $roomHTML = "";
  31.     $roomHTML .= '<select name="rooms" id="roomsDrop">'.PHP_EOL;
  32.     $roomHTML .= '<option value="">Please Select</option>'.PHP_EOL;
  33.    
  34.     $buildingname = $_POST['buildings'];
  35.     foreach ($buildings[$buildingname]['Rooms'] as $roomId => $roomData) {        
  36.         $roomHTML .= "<option value='".$roomId."'>" . $roomId . "</option>".PHP_EOL;        
  37.     }
  38.  
  39.     $roomHTML .= '</select>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement