我想从组合框中选择一个学年,然后用它来搜索所选年份的班级字母。但我需要将选定的文本放入一个变量中。
$yeardb = "SELECT DISTINCT `year` FROM `class`";
$do_year = mysqli_query($connectDB, $yeardb);
$num_year = mysqli_num_rows($do_year);
Year:
<form method="POST" >
<select id="yearCB" name="year" onchange="document.getElementById('selected_text').value=this.options[this.selectedIndex].text">
<?php
for ($i=0; $i<$num_year; $i++)
{
$yr = mysqli_fetch_array($do_year);
echo'<option value="'.$i.'">'.$yr ['year'].'</option>';
}
?>
</select>
<input type="hidden" name="selected_text" id="selected_text" />
</form>
<?php
if(isset($_POST['selected_text']))
{
$Value = $_POST['year'];
$make = mysql_real_escape_string($_POST['selected_text']);
}
$classdb = "SELECT `class` FROM `classes` WHERE `year` =".$make;
$do_class = mysqli_query($connectDB, $classdb);
$num_class = mysqli_num_rows($do_class);
?>