duanbu1998 2012-10-06 13:51
浏览 70
已采纳

如何正确设置页面结构

I am having trouble displaying the right details after a submit. I think my page structure is incorrect What is happening at moment is that if I click on the Module Submit button, nothing is being displayed which is incorrect.

Below is what is suppose to happen: (The page works in 3 parts)

Part 1: Contains a module drop down menu. User selects option from drop down menu and submits. Everytime it is submitted, it changes part 2 and part 3 is hidden. After submission drop down menu goes back to Please Select option.

Part 2: Contains Assessment drop down menu, only appears after user has submitted part 1. When this part is submitted by user selecting option from Assessment drop down menu and clicking on submit button, drop down menu goes back to Please Select and part 3 appears. Part 3 changes everytime part 2 is submitted with different options.

Part 3: Display details from part 2. Only appears and changes depending on Assessment chosen and submitted from part 2. If user submits from part 1, then this part is hidden.

Now my attempt is to seperate the php and phmtl from each other but like I said he problem is that no details is being displayed. Bear with me there is a lot of code but that is because I need to showw how my page is structured. My question is what things do I need to do in order to fix the page structure?

You can see what is happening with the application here: Application

Below is the code which goes in the order it is displayed in: (I tried to limit down as much as I can):

PHP:

         <?php

// connect to the database

$moduleactive = 1;

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


//excute query

$sqlnum = $sqlstmt->num_rows();

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

while ($sqlstmt->fetch()) {
    $moduleHTML .= sprintf('<option value="%1$s_%2$s_%3$s">%1$s - %2$s</option>' . PHP_EOL, $dbModuleNo, $dbModuleName, $dbModuleId);
}

$moduleHTML .= '</select>';

$pHTML = "";

//Module Submit (Part 1 Submitted)    
if (isset($_POST['moduleSubmit'])) {
    $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 SessionActive = ? AND Complete = ?) 
ORDER BY SessionName  
";

    $active   = 1;
    $complete = 1;

    //execute query 

    $sessionnum = $sessionqrystmt->num_rows();

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

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

}

//Session Submit (Part 2 Submitted)

if (isset($_POST['sessionSubmit'])) {
    $sessiondetailsquery = " 
    SELECT SessionId, SessionName 
    FROM Session 
    WHERE 
    (SessionId = ?) 
";

    //execute query

    $sessiondetailsqrystmt->bind_result($detailsSessionId, $detailsSessionName);

}

?> 

PHTML:

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


      <?php
    if ($step == 2) {
        if (!$_POST['moduleSubmit']) {
            if ($_POST['modules'] == '') {
    ?>  
               <span style='color: red'>Please Select a Module</span>  
           <?php
            } elseif (!$sqlnum) {
    ?>  
               <span style='color: red'>Sorry, You have No Assessments under this Module</span>  
            <?php
            } else {
    ?>  
        <p><strong>Assessments:</strong> {$sessionHTML} </p>   
        <p><input id='sessionSubmit' type='submit' value='View Assessment Details' name='sessionSubmit' /></p>  
         <?php
            }
        }
    }
    ?> 

      <?php
    if ($step == 3) {
        if (!$_POST['sessionSubmit']) {
            if ($_POST['session'] == '') {
    ?>  
               <span style='color: red'>Please Select an Assessment</span>  
            <?php
            } else {
    ?>   

    <table> 
    <tr> 
    <td></td> 
    <td><input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='$detailsSessionId' /></td> 
    </tr> 
    <tr> 
    <td><strong>Assessment:</strong></td> 
    <td>{$detailsSessionName}</td> 
    </tr> 
    </table> 
         <?php
            }
        }
    }
    ?> 

    </form> 

        </body> 
    </html>

UPDATE:

Notice: Undefined index: modules in ...on line 66
Notice: Undefined offset: 1 in ... on line 68 
Notice: Undefined offset: 2 in ... on line 69
Notice: Undefined index: modules in ... on line 116

PHP fiddle updated: http://phpfiddle.org/main/code/cbx-6mi

  • 写回答

1条回答 默认 最新

  • dreamact3026 2013-01-16 06:26
    关注

    I am not entirely sure about how you want the structure to be, but from what i could understand this is the answer to your question.

    You should see the structure, and hopefully you can use it =)

    The idea is to show a section depending on how much info the user have given us.

    And also allow the user to go back and change old data.

    I have commented out some of your "code", and added some options that you should remove. But this things should show you the structure suggested without you being forced to input your code.

    <html>
    <body>
    <form action="" method="post"> 
        <table> 
            <tr> 
                <th>
                    <?php
                        // connect to the database
                        //$sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo";
                        //excute query
                        //$sqlnum = $sqlstmt->num_rows();
                    ?>
                    Module: 
                    <select name="module" id="modulesDrop">
                        <option value="">Please Select</option>
                        <?php
                            /*
                            while ($sqlstmt->fetch()) {
                                echo sprintf('<option value="%1$s_%2$s_%3$s">%1$s - %2$s</option>' . PHP_EOL, $dbModuleNo, $dbModuleName, $dbModuleId);
                            }
                            */
                        ?>
                        <option value="test">test</option>
                    </select>
                </th> 
            </tr> 
        </table> 
        <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
    </form>
    <?php
    if(isset($_POST["module"]))
    {
    ?>
    <form action="" method="post"> 
        <input type="hidden" name="module" value="$_POST[module]">
        Assigments: 
        <?php
            $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 SessionActive = ? AND Complete = ?) 
            ORDER BY SessionName";
    
            //execute query 
    
            //$sessionnum = $sessionqrystmt->num_rows();
    
            if ($sessionnum == 0 && false) // "&& false" should ofcourse be removed
            {
            ?>
        <span style='color: red'>Sorry, You have No Assessments under this Module</span>
            <?php
            }
            else
            {
            ?>
        <select name="session" id="sessionsDrop">
            <option value="">Please Select</option>
            <?php
                /*
                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;
                }
                */
                echo "<option value='tst'>tst</option>";
            ?>
        </select>
        <br>
        <input type="submit" value="Submit Assigments">
    </form>
    <br>
    <br>
        <?php
        if(isset($_POST["session"]))
        {
            ?>
                <table> 
                    <tr> 
                        <td></td> 
                        <td><input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='$detailsSessionId' /></td> 
                    </tr> 
                    <tr> 
                        <td><strong>Assessment:</strong></td> 
                        <td>{$detailsSessionName}</td> 
                    </tr> 
                </table> 
            <?php
            }
        }
    }
    ?>
    </body>
    </html>
    

    If you only want one "step" to be shown at the time, use "else if" instead of "if" (of course it need a little more than that, but you should understand how to do it from that?)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗