Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to do a lot more in order to get this working as you said (ie, when you select one building you can select the rooms for that building). The difficulty is that PHP is not aware of what you have selected on the page once it has rendered the content.</p> <p>You can certainly get the second dropdown to display rooms from a specific building:</p> <p>On this line:</p> <pre><code>$buildings[$sqlrow['Building']]['Rooms'][] = $sqlrow['Room']; </code></pre> <p>You set the index to 'Building', not 0. For this reason, <code>$buildings[0]...</code> is, as the error says, undefined. If you change the foreach to: </p> <pre><code>foreach ($buildings[&lt;building name goes here&gt;]['Rooms'] as $roomId =&gt; $roomData) { $roomHTML .= "&lt;option value='".$roomId."'&gt;" . $roomId . "&lt;/option&gt;".PHP_EOL; } </code></pre> <p>Should work.</p> <p>However, to get the page to update the second dropdown after the first has been changed you'd need to either use AJAX or make the first dropdown post a response back to the page with a value, maybe something as simple as this:</p> <pre><code>$buildingname = $_POST['buildings']; foreach ($buildings[$buildingname]['Rooms'] as $roomId =&gt; $roomData) { $roomHTML .= "&lt;option value='".$roomId."'&gt;" . $roomId . "&lt;/option&gt;".PHP_EOL; } </code></pre> <p>You'd then need to add in a submit button to submit the first select, or possibly some javascript to submit the form when the selected item is changed - </p> <pre><code>$buildingHTML .= '&lt;select name="buildings" id="buildingssDrop" onchange="document.getElementById(\'dropDownForm\').submit()"&gt;'.PHP_EOL; </code></pre> <p>You'd then need to wrap the first select in form tags, with attributes in the opening tag of - </p> <pre><code>&lt;form action="" method="post"&gt; </code></pre> <p>And hopefully, if you got through all of that rather badly explained code, you should have something working!</p> <p>(Full code - untested - in case my explanation is too difficult to follow: <a href="http://pastebin.com/9UGx8nTX" rel="nofollow">http://pastebin.com/9UGx8nTX</a>)</p>
    singulars
    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. VO
      singulars
      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