由于无法找到会话,因此未显示“会话”下拉菜单

时间:2012-10-27 22:15:17

标签: php jquery

  

可能重复:
  How to display echo if user has not selected from a drop down menu

我无法显示“会话”下拉菜单。假设要发生的是教师从各自的下拉菜单中选择“课程”和“模块”。然后,当教师提交此内容时,它应显示“会话”下拉菜单,其中显示会话的名称,日期和时间。下拉菜单中显示的会话由从其下拉菜单中选择的模块和教师登录确定。

我遇到的问题是,无论我选择哪个模块或教师登录,它都找不到任何会话,因此它不会显示Sessions下拉菜单,但如果不能显示,则会显示echo消息找到任何会议“对不起,你在这个模块下没有会话。”

现在我测试了在SQL phpmyadmin中查找Sessions的查询,并在那里找到了会话,所以我的问题是为什么它不能找到任何会话,因此不会显示会话下拉菜单?

以下是代码:

<?php

// connect to the database
include('connect.php');

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
die();
}

$sql = "SELECT CourseId, CourseName FROM Course ORDER BY CourseId"; 

$sqlstmt=$mysqli->prepare($sql);

$sqlstmt->execute(); 

$sqlstmt->bind_result($dbCourseId, $dbCourseName);

$courses = array(); // easier if you don't use generic names for data 

$courseHTML = "";  
$courseHTML .= '<select name="courses" id="coursesDrop" onchange="getModules();">'.PHP_EOL; 
$courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

while($sqlstmt->fetch()) 
{ 
$course = $dbCourseId;
$coursename = $dbCourseName; 
$courseHTML .= "<option value='".$course."'>" . $course . " - " . $coursename . "</option>".PHP_EOL;  
} 

$courseHTML .= '</select>'; 

$moduleHTML = "";  
$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL; 
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  
$moduleHTML .= '</select>'; 


include('noscript.php');

?>

<script type="text/javascript">

function getModules() { 
var course = jQuery("#coursesDrop").val(); 
jQuery('#modulesDrop').empty(); 
jQuery('#modulesDrop').html('<option value="">Please Select</option>'); 
jQuery.ajax({ 
type: "post", 
url:  "module.php", 
data: { course:course }, 
success: function(response){ 
jQuery('#modulesDrop').append(response); 
} 
}); 


}

</script> 

<h1>EDIT AN ASSESSMENT'S DATE/START TIME</h1>    

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<tr>
<th>Course: <?php echo $courseHTML; ?></th>
<th>Module: <?php echo $moduleHTML; ?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit" name="moduleSubmit" /></p>
<div id="moduleAlert"></div>
</form>

<?php

if (isset($_POST['moduleSubmit'])) {

$sessionHTML = "";  

$sessionquery = "
SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId, TeacherId
FROM Session
WHERE
(ModuleId = ? AND TeacherId = ?)
ORDER BY SessionDate, SessionTime 
";

$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("ss",$moduleId,$userid);
// get result and assign variables (prefix with db)

$sessionqrystmt->execute(); 

$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbTeacherId);

$sessionqrystmt->store_result();

$sessionnum = $sessionqrystmt->num_rows();   

if($sessionnum ==0){
echo "<p>Sorry, You have No Sessions under this Module</p>";
} else { 

$dataArraySession = array();

while ( $sessionqrystmt->fetch() ) { 

$dataArraySession[$dbSessionId]['Sessions']['SessionName'] = $dbSesisonName['SessionDate'] = $dbSesisonDate['SessionTime'] = $dbSesisonTime; 

}

foreach ($dataArraySession as $sessionId => $sessionData) {

$sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;           
$sessionHTML .= "<option value='$sessionId'>" . $sessionData['SessionName']. " - " . $sessionData['SessionDate']. " - " . $sessionData['SessionTime'] ."</option>".PHP_EOL;        

}
$sessionHTML .= '</select>';

?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Sessions: <?php echo $sessionHTML; ?><input id="sessionSubmit" type="submit" value="Submit" name="sesionsubmit" /></p>      
</form>       

<?php
}

}

?>

下面是在“MOdule”下拉菜单中显示模块的代码。它使用jquery导航到module.php脚本,它在“模块”下拉菜单中显示正确的模块,具体取决于从“课程”下拉菜单中选择的课程:

<?php

         // connect to the database
     include('connect.php');

     /* check connection */
     if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
    }


    $course = isset($_POST['course']) ? $_POST['course'] : ''; 

    $sql = "
    SELECT cm.CourseId, cm.ModuleId, 
    c.CourseName,
    m.ModuleName
    FROM Course c
    INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
    JOIN Module m ON cm.ModuleId = m.ModuleId
    WHERE
    (c.CourseId = ?)
    ORDER BY c.CourseId, m.ModuleId
    "; 

     $sqlstmt=$mysqli->prepare($sql);

     $sqlstmt->bind_param("s",$course);

     $sqlstmt->execute(); 

     $sqlstmt->bind_result($dbCourseId,$dbModuleId,$dbCourseName,$dbModuleName);


    $moduleHTML  = "";  

     while($sqlstmt->fetch()) { 
        $moduleHTML .= "<option value='$dbModuleId'>" . $dbModuleId . " - " . $dbModuleName . "</option>".PHP_EOL;   
    } 


    echo $moduleHTML; 

     $sqlstmt->execute(); 


    ?>

0 个答案:

没有答案