0

I am trying to populate 3 menus, 1st menu is created from mysql query and php and displays TVshows ( ie. Modern Family, Dexter, etc ), what I would like to do is once the TVShow is selected populate the next drop down with a new mysql query for seasons ( 1 ,2 ,3 etc.) , then populate a 3rd drop down via mysql query based off the first 2 options being selected for episode

The table is as follows | id | Title | Season | Episode | Extension | URL

I can get the first drop down to display with the following code

<?php
$sql="Select distinct title from TVShows";
$result=mysql_query($sql);

echo "<select name='TVShow'><option value=''>Select TV Show</option>";
while($row = mysql_fetch_array($result))
{
echo    "<option value=$row[title]>$row[title]</option>";
}
echo "</select>";
?>

I have tried many examples but none seem to work right, I would like to be able to do this on the same page as opposed to having the user click submit to go to another page to select the second drop down.

I would like code to dynamically setup the 2nd dropdown based on the first choice, then dynamically setup the 3rd dropdown based on the 1st and second dropdowns

3
  • what your tables look like? maybe you can get all data in one query and just do the one loop Commented Dec 29, 2012 at 23:56
  • TVShow table is as follows | id | Title | Season | Episode | Extension | URL Commented Dec 30, 2012 at 0:00
  • you're looking for a cascading dropdown using ajax, check this tutorial: buffernow.com/cascading-dropdown-ajax Commented Dec 30, 2012 at 0:09

2 Answers 2

0

mysql_fetch_array does not fetch an associative array.

Try using mysql_fetch_assoc instead

Sign up to request clarification or add additional context in comments.

1 Comment

Looking for code to create 2nd and 3rd dropdowns dynamically based on previous dropdown selection, I will look into fetch_assoc though
0

For better performance on the user end you might consider loading all results from the db (and then ideally caching them) and then hiding and showing the appropriate ones with javascript.

This way if users are clicking on your menu a lot you're not making a ton of unnecessary round trips to the db.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.