在addstudentsession.php
下面我有一个下拉菜单,其中包含考试列表,我还有一个空的多选框,一个空的多选框:
//FROM VIEW SOURCE:
<select name="session" id="sessionsDrop">
<option value="">Please Select</option>
<option value='20'>EWYGC - 10-01-2013 - 09:00</option>
<option value='22'>WDFRK - 11-01-2013 - 10:05</option>
<option value='23'>XJJVS - 12-01-2013 - 10:00</option>
<option value='21'>YANLO - 11-01-2013 - 09:00</option>
<option value='24'>YTMVB - 12-01-2013 - 03:00</option>
</select> </p>
//FROM CODE:
$studentSELECT = "";
$studentSELECT .= '<select name="studenttextarea" id="studentselect" size="6">';
$studentSELECT .= '</select>';
//AJAX CODE:
$(document).ready( function(){
$('#sessionsDrop').change( function(){
var search_val = $(this).val();
$.post("addedstudents.php",
{studenttextarea : search_val},
function(data){
if (data.length>0){
$("#studentselect").html(data);
}
)};
现在假设发生的是,从下拉菜单中选择考试时,会激活ajax调用并导航到单独的php页面,在该页面中,它会运行查询以查看当前有多少学生在评估中。如果没有0名学生,则说明评估中没有学生,否则将显示考试中每个学生的别名和姓名。
我遇到的问题是,如果我选择了一个我认识的学生目前正在评估的评估,它仍会显示评估中没有学生的消息,而不是实际显示学生列表。别名和名字。我的问题是为什么它可以列出评估中的学生,而只是继续显示没有学生的信息?
我知道查询是正确的,因为我已经在phpmyadmin中测试了查询,它运行正常。以下是addedstudents.php
代码中的问题:
$session = isset($_POST['session']) ? $_POST['session'] : '';
$studentactive = 1;
$currentstudentqry = "
SELECT
ss.SessionId, st.StudentId, st.StudentAlias, st.StudentForename, st.StudentSurname
FROM
Student_Session ss
INNER JOIN
Student st ON ss.StudentId = st.StudentId
WHERE
(ss.SessionId = ? and st.Active = ?)
ORDER BY st.StudentAlias
";
$currentstudentstmt=$mysqli->prepare($currentstudentqry);
// You only need to call bind_param once
$currentstudentstmt->bind_param("ii",$session, $studentactive);
// get result and assign variables (prefix with db)
$currentstudentstmt->execute();
$currentstudentstmt->bind_result($dbSessionId,$dbStudentId,$dbStudentAlias,$dbStudentForename,$dbStudentSurname);
$currentstudentstmt->store_result();
$studentnum = $currentstudentstmt->num_rows();
$studentSELECT = "";
if($studentnum == 0){
$studentSELECT .= "<option disabled='disabled' class='red' value=''>No Students currently in this Assessment</option>";
}else{
while ( $currentstudentstmt->fetch() ) {
$studentSELECT .= sprintf("<option disabled='disabled' value='%s'>%s - %s s</option>", $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname) . PHP_EOL;
}
}
echo $studentSELECT;
答案 0 :(得分:1)
在$.post()
{}发送studenttextarea
,但在addedstudents.php
,您正在检查isset($_POST['session'])
,$session ==''
。
更改$.post()
=&gt;
{session : search_val},
或
addedstudents.php
=&gt;
$session = isset($_POST['studenttextarea']) ? $_POST['studenttextarea'] : '';
答案 1 :(得分:0)
看起来你没有设置$ _POST ['session']
使用firebug查看AJAX页面返回的内容,并转储$ _POST数据。看起来你只是在'studenttextarea'上发帖。