0

I have got these tables:

series:

id    title         year    .....    added
-----------------------------------------------------
1     series1s1     2000             2012.01.01.
2     series2s1     2010             2012.03.12.
3     series3s2     2003             2014.12.11.

episodes:

id    title         episode   .....    added
-----------------------------------------------------
1     series1s1     1                  2012.01.01.
2     series1s1     2                  2012.03.12.
3     series1s1     3                  2014.12.11.
4     series2s1     1                  2012.03.12.
5     series2s1     2                  2014.12.11.
7     series3s2     5                  2014.12.11.

I fill up a select option menu with titles:

<?php
$result = mysql_query("SELECT title, year FROM series ORDER BY added DESC");
$i = 0;
while ($row = mysql_fetch_object($result))
{
$series[$i] = $row->title. ' (' . $row->year . ')';
$i++;
}
?>

Then I write out:

<form method="post" action="newlink.php" enctype="multipart/form-data">    
<select name="seriestitle" style="color: rgb(0, 0, 0);"><?php foreach($series as $s)
{
echo"<option value = '$s' > $s </option>";
}
?>
</select>
...
The second select option menu here.
...
<input name="link" style=" color: rgb(0, 0, 0); width: 300" type="url">
...
<input value="Add" name="submit" type="submit">
</form>

I would like to create another select option menu that episode numbers which series selected with the first select option. For examle if I select series1s1 in the first select option menu I woud like to appear 1,2,3 in the second or if I select series2s1 appear 1,2.

I need something like this:

<?php 
$result2 = mysql_query("SELECT episode FROM episodes WHERE title = '".$_GET['seriestitle']."'");
$j = 0;
while ($row = mysql_fetch_object($result2))
{
$ep[$j] = $row->episode;
$j++;
}
?>
<select name="episodenums" style="color: rgb(0, 0, 0);"><?php foreach($ep as $e)
{
echo"<option value = '$e' > $e </option>";
}
?>
</select>

How can I get the actual selected option and refresh the second select option to show the correct episodes?

EDIT:

I found this: http://jsfiddle.net/x4ep8s9j/

But I have got tho select option menu and I need this script only for my first menu. And another question: Can I put in a PHP variable which this script write out?

Shifty
  • 112
  • 6
  • you are doing a query against get variables but your form is posting. But to answer your question, I would wrap the extra menu in an if checking for if the posted value is there – Pete Aug 18 '15 at 14:15
  • I was in the process of writing an answer when it was the question was closed. Hopefully this can help point you in the right direction: http://jsfiddle.net/jvwzbw9a/ – Pete Aug 18 '15 at 14:26

0 Answers0