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

4

2 回答 2

0

mysql_fetch_array does not fetch an associative array.

Try using mysql_fetch_assoc instead

于 2012-12-29T23:55:49.137 回答
0

为了在用户端获得更好的性能,您可以考虑从数据库加载所有结果(然后理想地缓存它们),然后使用 javascript 隐藏和显示适当的结果。

这样,如果用户经常单击您的菜单,您就不会对数据库进行大量不必要的往返。

于 2017-03-28T23:40:31.007 回答