现在我有两个下拉列表,一个是名称,另一个是时间。我希望当用户在第一个下拉框中单击所需的名称时,第二个下拉框中显示的时间应该属于第一个下拉框中选择的名称。
$con=mysqli_connect("localhost","root","123","fyp");
$query1 = mysqli_query($con,"SELECT fname FROM lecturer");
echo "Select lecturer:<select name= 'fname'>";
$name = 'fname';
$name = mysql_real_escape_string($name);
while($row=mysqli_fetch_array($query1))
{
echo "<option value='". $row['fname']."'>".$row['fname']. '</option>';
}
echo '</select>';
$con=mysqli_connect("localhost","root","123","fyp");
$query3 = mysqli_query($con,"SELECT stime FROM studbooking WHERE lecname is '$name'");
echo "Select Booking time:<select name= 'stime'>";
while($row=mysqli_fetch_array($query3))
{
echo "<option value='". $row['stime']."'>".$row['stime']. '</option>';
}
echo '</select>';
如何在sql查询中使用php变量?