0

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;
4

2 回答 2

1

$.post()你发送studenttextarea,但在addedstudents.php你检查isset($_POST['session']),所以$session ==''

更改其中一个$.post()=>

 {session : search_val}, 

或者

addedstudents.php=>

$session = isset($_POST['studenttextarea']) ? $_POST['studenttextarea'] : '';
于 2013-01-09T23:13:40.253 回答
0

看起来您没有设置 $_POST['session']

使用 firebug 查看 AJAX 页面返回的内容,并转储您的 $_POST 数据。看起来您只是在“studenttextarea”中发帖。

于 2013-01-09T23:04:14.370 回答