Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 生成foreach html输出变量_Php_Html_Mysql_Foreach - Fatal编程技术网

Php 生成foreach html输出变量

Php 生成foreach html输出变量,php,html,mysql,foreach,Php,Html,Mysql,Foreach,我在尝试找出最好的方法时遇到了问题。我正在创建一个模板/审查系统,允许用户填写模板,然后搜索已完成的审查。每个评论都标记在我需要显示的多个部分上 我的问题是,我需要在“slidingDiv”中列出每个单独的评论及其部分。目前,这会覆盖$htm变量,因此每次查看及其各自的部分在显示时都是完全相同的(因此使用不同的模板完成的每个部分应该是不同的)。我尝试使用数组,但这些数组被覆盖了。视觉上的想法是有一个表格来显示每个评论,然后当他们选择评论时,“slidingDiv”会在评论表格下面显示该评论的部分

我在尝试找出最好的方法时遇到了问题。我正在创建一个模板/审查系统,允许用户填写模板,然后搜索已完成的审查。每个评论都标记在我需要显示的多个部分上

我的问题是,我需要在“slidingDiv”中列出每个单独的评论及其部分。目前,这会覆盖$htm变量,因此每次查看及其各自的部分在显示时都是完全相同的(因此使用不同的模板完成的每个部分应该是不同的)。我尝试使用数组,但这些数组被覆盖了。视觉上的想法是有一个表格来显示每个评论,然后当他们选择评论时,“slidingDiv”会在评论表格下面显示该评论的部分

我意识到我离解决方案还很远,但这是我得到的最接近的解决方案。目前我有以下几点:

    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>";
}
if(isset($reviews)){
包括(“templates/default/pheader.php”);
echo“下面显示的搜索结果:

”; 回声“; 回声“; 回显“ECRConsultrantreviewerTemplateDate”; 回声“; foreach($reviews作为$review){ $ecr=$review->get_ecr(); $member=$review->get_team_member(); $user=$review->get_user(); $user\u name=$user->get\u name(); $template=$review->get_template(); $template_name=$template->get_name(); $member\u name=$member->get\u name(); $timestamp=$review->get_timestamp(); 回声“; 回声“; 回声“; 回声“; 回声“; 回显“$member_name”; 回声“; 回声“; 回显“$user_name”; 回声“; 回声“; 回显“$template_name”; 回声“; 回声“; 回显“$timestamp”; 回声“; 回声“; foreach($review->get_sections()作为$section){ $section\u name=$section->get\u name(); $section_total=$section->get_total(); $section_-mark=$section->get_-mark(); $section_pass=$section->get_pass(); 如果($section_pass==1){ $section_pass=“pass”; }否则{ $section_pass=“FAIL”; } $htm.=“$section\u name”; $htm.=“$section\u total/$section\u marks”; $htm.=“$section_pass”; } } 回声“; 回声“; 回声“; //列出每次审查的每个部分 回声“; 回声“

”; 回声“

”; }
看看代码,我很想先创建带有示例内容的html,以获得页面的感觉和您想要的最终结果。然后,一旦您满意了,就将php添加到第一个foreach块中,并使用var\u dumps或print\r命令测试您是否获得了正确的信息

一旦你满意了,就转到第二个foreach块,边测试边测试

尝试以这种方式组合代码和html总是有点令人望而生畏,像这样一小块一小块地工作可以让您对最终结果更有信心


我希望这能有所帮助。

为什么要将echo$template\u name写为echo“$template\u name”;没有真正的原因,除了我有其他的价值观在那里,还没有整理。使用模板引擎…这不是真正的问题,但谢谢。我知道它会是什么样子,这只是获取正确信息的逻辑。我想我必须在这里使用Ajax,并通过当前审查,然后以这种方式显示信息。