Note that there are some explanatory texts on larger screens.

plurals
  1. POsend select dropdown to another select dropdown
    text
    copied!<p>I'm making a website to learn coding and am making 2 select dropdowns that will have 1 be populated from the database table -> cat. The other select dropdown will be populated from table -> subcat. The database for cat and subcat look like this:</p> <p>Table Cat</p> <p>id (int 15) || cat(varchar 75) || number (int 3)</p> <p>Table Subcat</p> <p>id (int 15) || subcat(varchar 75) || catnumber (int 3)</p> <p>Every subcat row has a catnumber that corresponds with the row in cat -> number. So for example if we have Restaurants which is a row in Cat that has a number of 2, then if we also have American Food, and Chinese Food which have catnumber's of 2, then they are corresponding. </p> <p>Here's my code for pulling out of the database for all 3 of my cat dropdowns.</p> <pre><code>&lt;p&gt;&lt;b&gt;Cat1:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT id,cat FROM cat"; $result = mysql_query ($query); echo"&lt;select name='cselect1' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['cat'])."\"&gt;".$catinfo['cat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; &lt;!-- Next CAT --&gt; &lt;p&gt;&lt;b&gt;Cat2:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT id,cat FROM cat"; $result = mysql_query ($query); echo"&lt;select name='cselect2' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['cat'])."\"&gt;".$catinfo['cat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; &lt;!-- Next CAT --&gt; &lt;p&gt;&lt;b&gt;Cat3:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT id,cat FROM cat"; $result = mysql_query ($query); echo"&lt;select name='cselect3' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['cat'])."\"&gt;".$catinfo['cat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; </code></pre> <p>And here's my code for pulling out of the database for all 3 of my <strong>subcat</strong> dropdowns</p> <pre><code>&lt;p&gt;&lt;b&gt;Subcat1:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT * FROM subcat WHERE catnumber='1' "; $result = mysql_query ($query); echo"&lt;select name='sselect1' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['subcat'])."\"&gt;".$catinfo['subcat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; &lt;p&gt;&lt;b&gt;Subcat2:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT id,subcat FROM subcat WHERE catnumber='1' "; $result = mysql_query ($query); echo"&lt;select name='sselect2' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['subcat'])."\"&gt;".$catinfo['subcat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; &lt;p&gt;&lt;b&gt;Subcat3:&lt;/b&gt;&lt;br /&gt; &lt;?php $query="SELECT id,subcat FROM subcat WHERE catnumber='1' "; $result = mysql_query ($query); echo"&lt;select name='sselect3' class='e1'&gt;&lt;option value='0'&gt;Please Select A Category&lt;/option&gt;"; // printing the list box select command while($catinfo=mysql_fetch_array($result)){//Array or records stored in $nt echo "&lt;option value=\"".htmlspecialchars($catinfo['subcat'])."\"&gt;".$catinfo['subcat']."&lt;/option&gt;"; } echo"&lt;/select&gt;"; ?&gt; </code></pre> <p>So right now all of the subcat selects are trying to get all the subcategories for the cat with a number of 1 ( which is Restaurants ). How do I get whatever is selected on the cat select to make (without refreshing the page) the corresponding subcat select display the corresponding subcat list for the number of the cat?</p> <p>^ Very sorry for doing a terrible job explaining it. In the end I basically want it like Yelps -> <a href="http://www.yelp.com/biz_attribute?biz_id=Jsuy0DN6NhILXSkHr6UpCA" rel="nofollow">here</a></p> <p>Thanks for all help!</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