dtp0760 2013-05-29 10:10
浏览 45
已采纳

生成foreach html输出变量

I'm having a problem trying to work out the best way of doing this. I'm creating a template/review system which allows users to fill in a template and then search on reviews done. Each review is marked on multiple sections which I need to display.

My problem is that I need to list each separate review and it's section in the 'slidingDiv'. Currently this overwrites the $htm variable so each review & it's respective sections is exactly the same when displayed (each done using a different template therefore should be different). I tried using arrays but these were being overwritten. Visually the idea is to have a table which displays each Review and then when they select the Review the 'slidingDiv' shows the Sections of that Review below the Review table.

I realise I'm quite far off the solution but this was the closest I've been getting. Currently I have the below:

    if (isset($reviews)) {
    include ("templates/default/pheader.php");
    echo "<p>Search results displayed below:</p>";
    echo "<table id=table-search>";
    echo "<tr>";
    echo "<th>ECR</th><th>Consultant</th><th>Reviewer</th><th>Template</th><th>Date</th>";
    echo "</tr>";

    foreach ($reviews as $review) {
        $ecr = $review->get_ecr();
        $member = $review->get_team_member();
        $user = $review->get_user();
        $user_name = $user->get_name();
        $template = $review->get_template();
        $template_name = $template->get_name();
        $member_name = $member->get_name();
        $timestamp = $review->get_timestamp();

        echo "<tr>";
        echo "<td>";
        echo "<a href=\"#\" class=\"show_hide\">$ecr</a>";
        echo "</td>";
        echo "<td>";
        echo "$member_name";
        echo "</td>";
        echo "<td>";
        echo "$user_name";
        echo "</td>";
        echo "<td>";
        echo "$template_name";
        echo "</td>";
        echo "<td>";
        echo "$timestamp";
        echo "</td>";
        echo "</tr>";

        foreach ($review->get_sections() as $section) {
            $section_name = $section->get_name();
            $section_total = $section->get_total();
            $section_mark = $section->get_mark();
            $section_pass = $section->get_pass();
            if ($section_pass == 1) {
                $section_pass = "<font color = \"green\">PASS</font>";
            } else {
                $section_pass = "<font color = \"red\">FAIL</font>";
            }
            $htm .= "<tr><td>$section_name</td>";
            $htm .= "<td>$section_total / $section_mark marks</td>";
            $htm .= "<td>$section_pass</td></tr>";
        }
    }
    echo "</table>";
    echo "<div class=\"slidingDiv\">";
    echo "<table>";
    //List each section per Review
    echo "</table>";
    echo "<p><a href=\"#\" class=\"show_hide\">Hide</a></div></p>";
    echo "<p><a href=\"search.php\">Search Again</a></p>";
}
  • 写回答

1条回答 默认 最新

  • dpgui8229808 2013-05-29 14:18
    关注

    Looking at the code, I'd be tempted to create just the html first with sample content to get the feel of the page and the final result you're aiming for. Then, once you're happy, add the php to the first foreach block and test you're getting the right information using var_dumps or print_r commands.

    Once you're happy, move on to the second foreach block, testing as you go.

    Trying to do the code and html combined in this way will always be a bit daunting, working in bite size chunks like this enables you to be more confident of the end result.

    I hope this helps.

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

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路