Note that there are some explanatory texts on larger screens.

plurals
  1. POChained dropdown option not pulling previous values through in to query
    text
    copied!<p>I have found a example of chained dropdown boxes, however i am struggling to ensure that the 3rd box uses both the previous boxes in showing the required results.</p> <p>The boxes are intended to show the following, </p> <p>DROP DOWN BOX 1 = Select a sector</p> <p>DROP DOWN BOX 2 = Select a Level</p> <p>DROP DOWN BOX 3 = Select a Qualification</p> <p>On the last SQL query i have shown a $HELP, i think this is where im having my problems, i think it is loosing the previously stored value in dropdown box 1 when dropdown box 2 is selected.</p> <pre><code>&lt;?php //************************************** // Page load dropdown results // //************************************** function getTierOne() { $result = mysql_query("SELECT DISTINCT SSA1Text FROM qualifications ORDER BY SSA1Text ASC") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '&lt;option value="'.$tier['SSA1Text'].'"&gt;'.$tier['SSA1Text'].'&lt;/option&gt;'; } } //************************************** // First selection results // //************************************** if($_GET['func'] == "drop_1" &amp;&amp; isset($_GET['func'])) { drop_1($_GET['drop_var']); } function drop_1($drop_var) { include_once('db.php'); $result = mysql_query("SELECT DISTINCT Level FROM qualifications WHERE SSA1Text='$drop_var' ORDER BY Level ASC") or die(mysql_error()); echo '&lt;select name="drop_2" id="drop_2"&gt; &lt;option value=" " disabled="disabled" selected="selected"&gt;Choose one&lt;/option&gt;'; while($drop_2 = mysql_fetch_array( $result )) { echo '&lt;option value="'.$drop_2['Level'].'"&gt;'.$drop_2['Level'].'&lt;/option&gt;'; } echo '&lt;/select&gt;'; echo "&lt;script type=\"text/javascript\"&gt; $('#wait_2').hide(); $('#drop_2').change(function(){ $('#wait_2').show(); $('#result_2').hide(); $.get(\"func.php\", { func: \"drop_2\", drop_var: $('#drop_2').val() }, function(response){ $('#result_2').fadeOut(); setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400); }); return false; }); &lt;/script&gt;"; } {//************************************** // Second selection results // //************************************** if($_GET['func'] == "drop_2" &amp;&amp; isset($_GET['func'])) { drop_2($_GET['drop_var']); } function drop_2($drop_var) { include_once('db.php'); $result = mysql_query("SELECT * FROM qualifications WHERE Level='$drop_var' AND SSA1Text='$HELP'") or die(mysql_error()); echo '&lt;select name="drop_3" id="drop_3"&gt; &lt;option value=" " disabled="disabled" selected="selected"&gt;Choose one&lt;/option&gt;'; while($drop_3 = mysql_fetch_array( $result )) { echo '&lt;option value="'.$drop_3['Title'].'"&gt;'.$drop_3['Title'].'&lt;/option&gt;'; } echo '&lt;/select&gt; '; echo '&lt;input type="submit" name="submit" value="Submit" /&gt;'; } ?&gt; </code></pre> <p>Any help would be much appreciated.</p>
 

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