1

我很难知道哪些代码应该放在哪些页面中。

我想做的是以下几点:

  • 在页面中,用户从下拉菜单addstudentsession.php中选择评估#sessionsDrop

  • 每次从下拉菜单中选择评估时(或者换句话说,每次在下拉菜单中更改选项时),它都会对单独的页面执行 ajax 调用以addedstudents.php执行查询以查看哪些学生在所选评估中.

  • 从查询结果中进行评估的学生应该显示在多选框中addstudentsession.php(如果用户没有选择评估,我仍然希望显示一个空白的多选框addstudentsession.php

我的问题应该是每个代码的放置位置应该能够执行此操作,因为我根本没有做到这一点。根本没有出现多选框,我得到了一个未定义的变量。

以下是当前addstudentsession.php页面:

下拉式菜单:

$sessionHTML = '';

if($sessionnum ==0){
$pHTML = "<span style='color: red'>Sorry, You have No Assessments under this Module</span>";
} 

$sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;           

$studentInfo = array();

while ( $sessionqrystmt->fetch() ) {

$sessionHTML .= sprintf("<option value='%s'>%s - %s - %s</option>", $dbSessionId, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;    

}


$sessionHTML .= '</select>';

...

<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p><strong>Assessments:</strong> {$sessionHTML} </p>   
</form>";

多选框:

//getting undefined error below of studentSELECT
     $moduleexist="
        <form id='moduleExistForm'>
        <p><strong>Current Students in Chosen Assessment:</strong></p>
        <p>{$studentSELECT}</p>
        </form> 
        </div>";

        echo $moduleexist;

阿贾克斯调用:

        $('#sessionsDrop').change( function(){
            var search_val = $(this).val();
            $.post("addedstudents.php", 
            {studenttextarea : search_val}, 
            function(data){
   if (data.length>0){ 
     $("#studentselect").html(data); 
   }
)};

addedstudents.php以下是执行查询并在选择框中列出详细信息的当前页面:

<?php

$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($currentassessmentqry);
// You only need to call bind_param once
$currentstudentstmt->bind_param("ii",$sessionsdrop, $stuentactive);
// 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();   


$term = $_POST['studenttextarea'];


$studentSELECT = '<select name="studenttextarea" id="studentselect" size="6">'.PHP_EOL;      

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

}

$studentSELECT .= '</select>';

?>
4

1 回答 1

0

在你的addedstudents.php你必须返回值$studentSELECT。添加一个

echo $studentSELECT

在你的 PHP 结束时。

你也永远不会$term = $_POST['studenttextarea'];在你的 PHP 代码中使用任何地方。此外$sessionsdrop,在任何地方都没有定义,$stuentactive可能是一个错字 ( $studentactive)。同样适用于$currentstudentqryvs $currentassessmentqry

于 2013-01-09T21:02:21.607 回答