When posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.
As for your issue, take a look at your while() loop where you process the results from the SQL query:
while($num<=5)
{$sem= $semester[$num]." ".$year; $num=$num+1;}
Here, you're constantly overwriting the value of the $sem variable without ever using the previous values. Thus, the only thing you're going to be left with is the last result from the result set.
Furthermore, note that you're missing some basic HTML syntax too... <select> elements should have one or more <option> children nodes (whereas you aren't outputting any in your code).