Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically populate mysql array into drop down menu
    primarykey
    data
    text
    <p>I have a database that I want to get data out onto a website. It contains states listed by name and id. Counties listed by id, namne , and state that contains thems ID and then clubs that exist , with a reference to the county id's that they exist in and columns for their actual data.</p> <p>What I've got :</p> <p>A drop down menu that populates itself with state id and name.</p> <p>What I'd like to accomplish:</p> <p>On selection of state , let's say ny , take it's id and use this in gathering another mysql array for the county drop down. I'd like it to dynamically occur on selection of state , maybe even giving a count of results next to the drop down.</p> <pre><code>$resstate = mysql_query("SELECT * FROM state ORDER by longstate;") or die("Note: " . mysql_error()); State: &lt;select name="State" size=1&gt; &lt;? while( $rs = mysql_fetch_array( $resstate ) ) { echo "&lt;option value=" .$rs['id'] . "&gt;" . $rs['longstate'] . "&lt;/option&gt;"; } echo "&lt;/select&gt;"; ?&gt; </code></pre> <p>I know I could use a JavaScript <code>onChange="this.form.submit()"</code> on the first drop down, but it's my understanding that I'd then be making a new page at that point and don't know if I could keep the functionality of the state drop down, say if you accidentally chose new Hampshire when you wanted New York.</p> <p>here's an example of the current array filling the drop down :</p> <p><a href="http://snowmobileamerica.com/countytest.php" rel="nofollow">http://snowmobileamerica.com/countytest.php</a></p> <p>----EDIT---</p> <p>Using Dagons Advice , I looked into Ajax.</p> <p>I made a php file that's supposed to query the database based on a reference to getcounty.php?q=</p> <p>The file is created as follows :</p> <pre><code>&lt;?php $q=$_GET["q"]; $cn=mysql_connect("localhost","user","password") or die("Note: " . mysql_error()); mysql_select_db("snowusa_clubs", $cn); $sql="SELECT * FROM county WHERE state_id = '".$q."' ORDER by name"; $result = mysql_query($sql); echo "&lt;select name="County" size=1&gt;"; while($rc = mysql_fetch_array($result)) { echo "&lt;option value=" .$rc['id'] . "&gt;" . $rc['name'] . "&lt;/option&gt;"; } echo "&lt;/select&gt;"; mysql_close($cn); ?&gt; </code></pre> <p>If i try to run it manually <a href="http://www.snowmobileamerica.com/getcounty.php?q=33" rel="nofollow">http://www.snowmobileamerica.com/getcounty.php?q=33</a> I get a 500 internal server error... </p> <p>Any ideas where I went wrong?</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.
 

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