Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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 循环结束后回音,而不是循环时回音_Php_Loops_Mysqli_Echo_Forum - Fatal编程技术网

Php 循环结束后回音,而不是循环时回音

Php 循环结束后回音,而不是循环时回音,php,loops,mysqli,echo,forum,Php,Loops,Mysqli,Echo,Forum,我正在编写自己的论坛代码(出于学习原因),并试图找到以下问题的解决方案: 我将论坛帖子存储在数据库中,当我想显示这些帖子时,我首先将mySQL中的每个帖子放入一个数组($posts[][]),然后循环通过这些数组将它们输出到htmlpage: if (count($posts) > 0) { for ($x = 0; $x < count($posts); $x++) { echo ' <div class="post-header"&g

我正在编写自己的论坛代码(出于学习原因),并试图找到以下问题的解决方案:

我将论坛帖子存储在数据库中,当我想显示这些帖子时,我首先将mySQL中的每个帖子放入一个数组($posts[][]),然后循环通过这些数组将它们输出到htmlpage:

if (count($posts) > 0) {
    for ($x = 0; $x < count($posts); $x++) {
        echo '
        <div class="post-header">' . $posts[$x][3] . '<text style="float:right">#' . ($x+1) . '</text></div>
        <div class="post">
            <div class="post-user ">';
            if(login_check($mysqli) && (permission_check($mysqli) == 2 || permission_check($mysqli) == 3 || $username == $posts[$x][5])) {
                echo '<a href="posting.php?topicID='. $topicID . '&forumID=' . $forumID . '&postID=' . $posts[$x][1] . '&mode=edit">Edit</a><br>';
            }
            echo '<a href="../profile/?profile="' . $posts[$x][5] . '">' . $posts[$x][5] . '</a>
            <br>
            </div>
            <div class="post-text">' . $bbcode->parse($posts[$x][4]) . '</div>
        </div><br>';
    }
}
if(计数($posts)>0){
对于($x=0;$x”;
}
回声'

“.$bbcode->parse($posts[$x][4])”
",; } }
虽然这运行得很好,但我希望回声仅在循环完成后显示。目前,这会实时回响,每个论坛帖子都会被添加到html中,直到循环完成,看起来加载速度非常慢。

请尝试此方法

$responseString = '';
if (count($posts) > 0) {
    for ($x = 0; $x < count($posts); $x++) {
        $responseString .= '
        <div class="post-header">' . $posts[$x][3] . '<text style="float:right">#' . ($x+1) . '</text></div>
        <div class="post">
            <div class="post-user ">';
            if(login_check($mysqli) && (permission_check($mysqli) == 2 || permission_check($mysqli) == 3 || $username == $posts[$x][5])) {
                $responseString .= '<a href="posting.php?topicID='. $topicID . '&forumID=' . $forumID . '&postID=' . $posts[$x][1] . '&mode=edit">Edit</a><br>';
            }
            $responseString .= '<a href="../profile/?profile="' . $posts[$x][5] . '">' . $posts[$x][5] . '</a>
            <br>
            </div>
            <div class="post-text">' . $bbcode->parse($posts[$x][4]) . '</div>
        </div><br>';
    }
}
echo $responseString;
$responseString='';
如果(计数($posts)>0){
对于($x=0;$x
$responseString='';
如果(计数($posts)>0){
对于($x=0;$x
if(计数($posts)>0){
$sexy='';
对于($x=0;$x
if(计数($posts)>0){
$sexy='';
对于($x=0;$x