加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

功能结构不遵循问题(PHP)

发布时间:2020-12-13 22:47:15 所属栏目:PHP教程 来源:网络整理
导读:?php PickModule(); // Show the thing to pick module if(ModuleIsSubmitted()) // When module is picked { PickSession(); // Show the thing to pick session if(SessionIsSubmitted()) // When session is picked { ShowAssessment(); // Show students
<?php


        PickModule(); // Show the thing to pick module

        if(ModuleIsSubmitted()) // When module is picked
        {
            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();
                }

            }

        }



    ?>

我试图遵循这样的页面结构:

>显示PickModule()
>当用户在PickModule()函数中提交时,它将检入if(ModuleIsSubmitted())然后输出CheckSession()中的check结果
>显示PickSession()
>当用户在PickSession()函数中提交时,它将检查if(SessionIsSubmitted())然后输出ShowAssessment()中的check结果
>显示ShowAssessment()
>当用户在ShowAssessment()函数中提交时,它将检查if(StudentAnswersIsSubmitted())以检查是否单击了提交按钮,然后在StudentAnswers()中输出结果
>显示StudentAnswers()

我遇到的问题是最后两个要点,当单击answerSubmit按钮并在if(StudentAnswersIsSubmitted())中检查时,然后直接返回到PickModule(),而不是在StudentAnswers()中显示结果功能.我究竟做错了什么?

下面是通过每个函数的代码:

这是以下代码的演示:DEMO

function PickModule()
{ ?>
    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> 
        <?php            
        $moduleactive = 1;

        $sql = "SELECT ModuleId,ModuleNo,ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; 

        //mysqli code for modules drop down menu

        ?>
        <strong>Module:</strong>
        <select name="module" id="modulesDrop">
            <option value="">Please Select</option>
            <?php
            while($sqlstmt->fetch()) { 
                $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; 
                if(isset($_POST["module"]) && $ov == $_POST["module"]) 
                    echo "<option selected='selected' value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL; 
                else 
                    echo "<option value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
             } 
            ?>
        </select>
        <br>
        <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
    </form>
<?php }
function ModuleIsSubmitted()
{
    if(isset($_POST["module"]) && empty($_POST["module"])) // We picked the "Please select" option
    { ?>
            Please Select a Module
    <?php 
        return false;
    }
    else if(!isset($_POST["module"]))
    {
        return false;
    }
    else // All is ok
    {
        return true;
    }
    return false;
}
function PickSession()
{

    $dataTransfered = explode( "_",$_POST["module"] );
    $moduleNo = $dataTransfered[0];
    $moduleName = $dataTransfered[1];
    $moduleId = $dataTransfered[2];

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

//mysqli code for assessments drop down menu  

    ?>

    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> 
        <input type="hidden" name="module" value="<?php echo $_POST['module']; ?>">
        <p>
            <strong>Selected Module: </strong><?php echo $moduleNo ." - ". $moduleName; ?> 
        </p>
    <?php if ($sessionnum == 0 ){ ?>
        <div class="red">
            Sorry,You have No Assessments under this Module
        </div>
    <?php } else { ?>
           <p>
        <strong>Asessments:</strong>
        <select name="session" id="sessionsDrop">
            <option value="">Please Select</option>
            <?php
                while ( $sessionqrystmt->fetch() ) {
                    $sv = $dbSessionId;
                    if($dbSessionActive == 0){
                        $class = 'red';
                    }else{
                        $class = 'green';   
                    }
                    if(isset($_POST["session"]) && $sv == $_POST["session"]) 
                        echo "<option selected='selected' value='$sv' class='$class'>" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
                    else
                        echo "<option value='$sv' class='$class'>" . $dbSessionName . " - " . date('d-m-Y',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
        { ?>
            <div class="red">
                Please Select an Assessment
            </div>
        <?php 
            return false;
        }
    else if(!isset($_POST["session"]))
    {
        return false;
    }
    else // All is ok
    {
        return true;
    }
    return false;

}


function ShowAssessment()
{   

$studentactive = 1;

$currentstudentqry = "
SELECT
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
";

//mysqli code for students drop down menu


if($studentnum == 0){ ?>

<div class="red">
There are no Students who have currently taken this Assessment
</div>
<?php } else { 

$questionsqry = "
SELECT
QuestionId,QuestionNo
FROM
Question
WHERE
(SessionId = ?)
ORDER BY QuestionNo
";

//mysqli code for questions drop down menu

        ?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">         
<p>
<input type="text" name="session" value="<?php echo $_POST['session']; ?>">
<strong>Student:</strong>
<select name="student" id="studentsDrop">
<option value="All">All</option>
<?php
while ( $currentstudentstmt->fetch() ) {
$stu = $dbStudentId;
if(isset($_POST["student"]) && $stu == $_POST["student"]) 
    echo "<option selected='selected' value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL;
else
    echo "<option value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL;
}
?>
</select>
</p>

<p>
<strong>Question:</strong>
<select name="question" id="questionsDrop">
<option value="All">All</option>
<?php
while ( $questionsstmt->fetch() ) {
$ques = $dbQuestionId;
if(isset($_POST["question"]) && $ques == $_POST["question"]) 
    echo "<option selected='selected' value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL;
else
    echo "<option value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL;
}
?>
</select>
</p>

<input id="answerSubmit" type="submit" value="Get Student's Answers" name="answerSubmit" />
</form>

<?php
}
}

function StudentAnswersIsSubmitted()
{

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

}

function StudentAnswers()
{

echo "student answers";

}

?>

解决方法

我想我在这里看到错误,在PickSession函数中你有这行代码,在表单中,

<input type="hidden" name="module" value="<?php echo $_POST['module']; ?>">

这会将指定的模块重新发布回脚本,您在ShowAssessment函数下缺少此行,因此当用户提交“Get Student’s Answers”表单时,表单中的数据不会被发布.请注意,您还必须在表单中重新发布会话变量,因为我看到您已经完成但我认为您希望将其设置为隐藏字段,

function ShowAssessment()
{
    //Sql...

     //Line 169 of bottom code sample
     <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">         
     <p>
        <input type="hidden" name="module" value="<?php echo $_POST['module']; ?>">
        //type="hidden" not "text"    
        <input type="hidden" name="session" value="<?php echo $_POST['session']; ?>">

        //Rest of code...
}

我相信添加它会修复您的代码.请注意,您必须不断重新发布所有先前提交的数据,以维护此代码结构.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读