while循环fetch()语句中没有输出

时间:2013-02-06 20:12:24

标签: php mysqli

我在下面有一个php / mysqli代码,它不显示while循环fetch()语句中的任何回声。现在查询已在SQL中测试,查询输出的结果是一行,但为什么不能将结果输出到回声屏幕上?

下面我将展示构造的代码和视图页面源代码:

代码构造:

    if ((isset($studentusername)) && (isset($studentid))){ 

                include('studentname.php');

                ?>

                <div class="topcorner"><a id="studentmenulink" href="studentmenu.php">Back to Menu</a></div>


                <?php
                include('noscript.php');
                ?>      


                <?php

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

        $sessionquery = "
        SELECT s.SessionId, SessionName, SessionDuration, SessionDate, SessionTime, TotalMarks, SessionWeight, 
        PenaltyEnabled, s.ModuleId, ModuleNo, ModuleName, st.StudentId, StudentAlias, StudentForename, StudentSurname
        FROM Penalty p
        INNER JOIN Session s ON p.SessionId = s.SessionId
        INNER JOIN Module m ON s.ModuleId = m.ModuleId
        LEFT JOIN Student_Session ss ON s.SessionId = ss.SessionId
        INNER JOIN Student st ON ss.StudentId = st.StudentId
        WHERE
        (s.SessionId = ? AND st.StudentId = ?)
        ";

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

        $sessionqrystmt->execute(); 

        $sessionqrystmt->bind_result($dbSessionId,$dbSessionName, $dbSessionDuration, $dbSessionDate, $dbSessionTime, $dbTotalMarks, $dbSessionWeight, 
        $dbPenaltyEnabled, $dbModuleId, $dbModuleNo, $dbModuleName, $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname);

        $sessionqrystmt->store_result();
        $sessionqrynum = $sessionqrystmt->num_rows();    
        ?>
        <form action='results.php' method='post' id='exam'>

         <?php 
         while ($sessionqrystmt->fetch()) {
        echo "<p><input type='text' id='studentId' name='studentId' value='$dbStudentId' /></p>";
        echo "<p>Student: " . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "<br/>";
        echo "Module: " . $dbModuleNo . " - " . $dbModuleName . "<input type='text' id='moduleId' name='moduleId' value='$dbModuleId' /><br/>";
        echo "Assessment: " . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "<input type='text' id='sessionId' name='sessionId' value='$dbSessionId' /></p>";
        echo "<p><span id='countdown'>" . $dbSessionDuration . "</span></p>";

        }
        echo $sessionquery;
        ?>
        </form>
<?php
}else{ 

echo "Please Login to Access this Page | <a href='./studentlogin.php'>Login</a>";
}

?>

在视图页面来源:

<body>



   Logged In: <b>Joe Fitzpatrick</b> | <a id='studentlogout' href='./studentlogout.php'>Logout</a>      
        <div class="topcorner"><a id="studentmenulink" href="studentmenu.php">Back to Menu</a></div>


        <noscript style='color: red'><img src="Images/warning-2.fw.png" alt="Javascript Warning" id="warningImage" name="warningSymbol"/> In order to use this application without any problems, you must have javascript enabled</noscript>



        <form action='results.php' method='post' id='exam'>

 </form>
</body>

您可以看到视图页面源中的表单标记内没有输出任何内容,这就是回声所在的位置。

0 个答案:

没有答案