如何循环或预测它

时间:2014-11-23 12:22:51

标签: php mysqli

我无法预测循环我的评论&回复系统。我阅读了很多文章和例子,但不能在我的案例中应用这些。

这是我的回复评论系统,这里每个想法都运作良好。但回复表仅适用于最后/新评论。所以我需要循环每个评论。但是不能帮助我。

global $dbh;

$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_error($dbh));

echo'<div class="comments"><div id="updates"><div class="content"><comment>';

// Show only main comment

while($row = mysqli_fetch_array($results)) 
{   $id = $row['id'];
    $qazi_id = $row['qazi_id'];
    $username = $row['username'];
    $description = $row['description'];     
    $parent_id = $row['parent_id'];
    $date = $row['date'];
//echo comment
    echo'<div class="comment">
            <div class="cdomment_cheder">';
    echo'<p><a href="#"  title="">'.$username.'</a> Says:</p>';
    echo'<span>'.$date.'</span><br/>
        <div class="avatarcnt">
            <img alt="" src="uploadprofile/'.$u_imgurl.'"/>
        </div></div></div>
        <div class="cdomment_text">';
        if ($description=="") {echo '';}
        else echo''.htmlentities($description).'<br>';
        echo '</div>';

//reply
echo'<div class="reply_box"><a href="javascript: void(0)" class="reply" id="'.$id.'">Reply</a></div>';

//Reply form

echo'<div id="loader"></div><div class="reply_here" id="reply_here-'.$id.'" style="display:none;">
        <form action="" method="post" id="repfrm" enctype="multipart/form-data">
            <fieldset id="cmntfs">
                <input type="hidden" name="username" tabindex="1" id="author" value="'.$username.'"/>
                <textarea name="replycom" rows="2" tabindex="4" id="replycom" value=""></textarea>
                <input type="hidden" name="parent_id" id="parent_id" value="0" />
                <input type="hidden" name="tutid2" id="tutid" value="'.$tutid2.'" />
                <button type="submit" name="submit" value="" tabindex="5" id="submit" class="repfrm">Post Reply</button>
            </fieldset>
        </form>
    </div>';

// Show Reply of each comment
$query = "SELECT * FROM comments_reply WHERE parent_id ='".$id."'";
$res = mysqli_query($dbh,$query);
while($row = mysqli_fetch_array($res)) 
{   $id = $row['id'];
    $qazi_id = $row['qazi_id'];
    $username = $row['username'];
    $description = $row['description'];     
    $parent_id = $row['parent_id'];
    $date = $row['date'];
//echo reply
        echo' <div class="rcontent"><replycomment><ul>
            <div class="comment">
            <div class="cdomment_cheder">';
echo'<p class="name"><a href="#" title="">'.$username.'</a> Says:</p>';
            echo'<span>'.$date.'</span><br/>
                <div class="avatarcnt">
                    <img alt="" src="uploadprofile/'.$u_imgurl.'"/>
                </div></div></div>
                <div class="cdomment_text">';
                    if ($description=="") {echo '';}
                    else echo''.htmlentities($description).'<br>';
            echo '</div>';
            echo'</ul><replycomment></div>';

        }   //reply while close 
    }   //comment while close
    echo'</div><comment></div>';

0 个答案:

没有答案