Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you sure the post value for the building is set.</p> <p>since you told that the sql output shows no value for the building parameter, it is sure that $building will be null. You need to pass the post value to the $building </p> <p>You need to change your code like this:</p> <pre><code>if(isset($_POST['buildings'])){ $building = $_POST['buildings']; } else { $building = ''; } $sql="SELECT Building, Room FROM Room WHERE Building = '".$building."'"; $sqlresult = mysql_query($sql); $buildings = array(); // easier if you don't use generic names for data while($sqlrow = mysql_fetch_array($sqlresult)) { // you need to initialise your building array cells if (!isset($buildings[$sqlrow['Building']])) { $buildings[$sqlrow['Building']] = array('Rooms' =&gt; array()); } // you can add the room to the building 'Rooms' array $buildings[$sqlrow['Building']]['Rooms'][] = $sqlrow['Room']; } $buildingHTML = ""; $buildingHTML = "&lt;form action=\"\" method=\"post\"&gt;"; $buildingHTML .= '&lt;select name="buildings" id="buildingssDrop" onchange="document.getElementById(\'dropDownForm\').submit()"&gt;'.PHP_EOL; $buildingHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL; foreach ($buildings as $building =&gt; $buildingData) { $buildingHTML .= "&lt;option value='".$building."'&gt;" . $building . "&lt;/option&gt;".PHP_EOL; } $buildingHTML .= '&lt;/select&gt;'; $buildingHTML .= '&lt;/form&gt;'; $roomHTML = ""; $roomHTML .= '&lt;select name="rooms" id="roomsDrop"&gt;'.PHP_EOL; $roomHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL; if(isset($_POST['buildings'])){ $buildingname = $_POST['buildings']; foreach ($buildings[$buildingname]['Rooms'] as $roomId =&gt; $roomData) { $roomHTML .= "&lt;option value='".$roomId."'&gt;" . $roomId . "&lt;/option&gt;".PHP_EOL; } } $roomHTML .= '&lt;/select&gt;'; echo $buildingHTML; echo $roomHTML; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload