我有一个问题是从2个选项中获取2个值,这些值链接到基于所选选项读取数据库的新页面。
如果我选择了第4年和2015年,单击VIEW按钮后的下一页应该是一个包含4个属性(姓名,ID,标记和成绩)的表,位于学生表中。
如何解决这个问题?
html的一部分:
<form role="form" action="" method="post" enctype="multipart/form-data">
<?php choose_first_class(); ?>
<div class="form-group">
<label>Year of Study</label>
<select class="form-control" name="option1">
<option>Choose one</option>
<option value="4">Year 4</option>
<option value="5">Year 5</option>
<option value="6">Year 6</option>
</select>
</div>
<div class="form-group">
<label>Year of Class</label>
<select class="form-control" name="option2">
<option>Choose one</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select>
</div>
<center><button type="submit" name="choose" class="btn btn-primary">View</button></center>
</form>
部分功能:
function choose_first_class(){
if(isset($_POST['choose'])){
if ('option1' == "4" && 'option2' == "2015"){
$query = "SELECT * FROM student WHERE student_year = 'T4'' AND study_year = '2015' AND group = 'FIRST' ";
redirect("a.php");
}
else if ('option1' == "4" && 'option2' == "2016"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("b.php");
}else if ('option1' == "4" && 'option2' == "2017"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("c.php");
}else if ('option1' == "5" && 'option2' == "2015"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("d.php");
}else if ('option1' == "5" && 'option2' == "2016"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("e.php");
}else if ('option1' == "5" && 'option2' == "2017"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("f.php");
}else if ('option1' == "6" && 'option2' == "2015"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("g.php");
}else if ('option1' == "6" && 'option2' == "2016"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("h.php");
}else if ('option1' == "6" && 'option2' == "2017"){
$query = "SELECT * FROM student WHERE student_year = 'T4' AND study_year = '2015' AND group = 'FIRST' ";
redirect("i.php");
}
else
echo "try again";
}
}