0

这是一个演示DEMO

在演示中,选择一个评估,提交它,然后当学生和问题下拉菜单出现时,单击另一个提交按钮。您将看到一个未定义的变量出现。我正在尝试做的是从Assessment下拉菜单中回显评估名称、数据和时间。但这怎么能做到呢?

下面是相关代码:

   function PickSession() 
        {
            //ASSESSMENT DROP DOWN MENU:

            //Get data from database
            $sessionquery = "
                SELECT s.SessionId, SessionName, SessionDate, SessionTime, SessionActive, Complete
                FROM Session s
                INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
                WHERE
                (Complete = ?)
                ORDER BY SessionName 
                ";
            $complete = 1;

            global $mysqli;
            $sessionqrystmt=$mysqli->prepare($sessionquery);
            // You only need to call bind_param once
            $sessionqrystmt->bind_param("i",$complete);//it doesn't recognse $userid
            // get result and assign variables (prefix with db)
            $sessionqrystmt->execute(); 
            $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbSessionActive, $dbComplete);
            $sessionqrystmt->store_result();

            ?>

            <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> 
                   <p>
                <strong>Asessments:</strong>
                <select name="session" id="sessionsDrop">
                    <option value="">Please Select</option>
                    <?php
                        while ( $sessionqrystmt->fetch() ) {
                            $sv = $dbSessionId;
                            if(isset($_POST["session"]) && $sv == $_POST["session"]) 
                                echo "<option selected='selected' value='$sv'>" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
                            else
                                echo "<option value='$sv'>" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
                        }
                    ?>
                </select>
                </p>
                <input id="sessionSubmit" type="submit" value="Submit Assessments" name="sessionSubmit" />
            </form>
        <?php
        }

    --------------------------------------------------------------------

        function SessionIsSubmitted()
        {
                if(isset($_POST["session"]) && empty($_POST["session"])) // We picked the "Please select" option
                { ?>

                        Please Select an Assessment

                <?php 
                    return false;
                }
            else if(!isset($_POST["session"]))
            {
                return false;
            }
            else // All is ok
            {
                return true;
            }
            return false;

        }

    --------------------------------------------------------------------

        function ShowAssessment()
        {   

        //STUDENT AND QUESTION DROP DOWN MENU GO HERE
        //button - name='answerSubmit' goes here

        }

    --------------------------------------------------------------------

        function StudentAnswersIsSubmitted()
        {

        if(!isset($_POST["answerSubmit"]))
            {
                return false;
            }
            else // All is ok
            {
                return true;
            }
            return false;

        }

    --------------------------------------------------------------------

        function StudentAnswers()
        {

        echo $dbSessionName . " - " . $dbSessionDate . " " . $dbSessionTime;

        }

        ?>

Below is functions structure:

    <?php


            PickSession(); // Show the thing to pick session
            if(SessionIsSubmitted()) // When session is picked
            {
              ShowAssessment(); // Show students and questions information
              if(StudentAnswersIsSubmitted()) // Student Answers button is submitted
                {
                  StudentAnswers();
                }

            }



    ?>
4

1 回答 1

0

您不能通过放置数组变量来打印一个选定的元素$dbSessionName。所有评估都存储在此数组中,您希望通过放置数组变量来打印选定的评估。尝试仅打印已选择的数组元素。这样做:

<select name="session[]" id="sessionsDrop">
if (isset($_POST['Submit']) == 1) {

    $session_name = $_POST['session'];
        echo $session;
    }
于 2013-01-31T04:51:37.687 回答