• 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
اصلاح حلقه کد
#1
سلام
یه کد برای بخش نظرات توشتم ولی هر پاسخی که کامنت ها میدم زیر کامنت کاربر نمی افته و همه ی پاسخ ها در پایین می افتن و کامنت کاربران همشون در بالا
میشه راهنمایی کنید ؟
تصویر قسمت کامنت ها را پیوست کردم ببینید چطوریه

فکر کنم مشکلم توی جایگزاری حلقه ها هست
کد پی‌اچ‌پی:
<div class="container">
 
                   <div class="row justify-content-center">
 
                       <div class="col-lg-12">


 
                           <?php
                            $cm_a 
"
                    SELECT user_tbl.id,user_tbl.name_family, comments_tbl.user_id, comments_tbl.ctime, comments_tbl.comment_id, comments_tbl.cparent_id,comments_tbl.cdate,comments_tbl.cstatus,comments_tbl.comment
                    FROM user_tbl
                    INNER JOIN comments_tbl
                    ON user_tbl.id=comments_tbl.user_id WHERE post_id='
$p' AND cstatus='1'  ORDER BY id DESC;
                    "
;
 
                           $cm_q mysqli_query($conn$cm_a);
 
                           $crow mysqli_num_rows($cm_q);
 
                           if ($crow >= 1) {
 
                           ?>


                            <!--comments area start-->
                            <div class="comments">
                                <h2 class="comments-title"> نظرات</h2>

                                <ul><?php while ($cm_row mysqli_fetch_assoc($cm_q)):
 
                                       ?>
                                        <li class="comment">
                                            <?php if ($cm_row['cparent_id'] == null) :
 
                                               ?>
                                                <article class="comment-body">
                                                    <footer class="comment-meta">
                                                        <div class="comment-author">
                                                            <img alt="" src="assets/img/team/t-1.jpg" class="">
                                                            <b class="fn">
                                                        <span class="text-primary">
                                                                    <?php echo $cm_row['name_family']; ?>
                                                                </span>
                                                            </b>
                                                        </div>
                                                        <!-- .comment-author -->

                                                        <div class="comment-metadata">
                                                            <small>
                                                                <?php echo "<badge class='badge-pill badge-primary'>تاریخ " $cm_row['cdate'] . " در ساعت " $cm_row['ctime'] . "</badge>"?>
                                                            </small>
                                                        </div><!-- .comment-metadata -->

                                                    </footer><!-- .comment-meta -->

                                                    <div class="comment-content">
                                                        <?php echo nl2br($cm_row['comment']); ?>
                                                    </div><!-- .comment-content -->

                                                </article><!-- .comment-body -->

                                            <?php endif; ?>

                                            <?php
                                            if 
($cm_row['cparent_id'] != NULL && $cm_row['cstatus'] == '1' && $cm_row['cparent_id'] = $cm_row['comment_id']): ?>

                                                <ul class="children">
                                                    <li class="comment ">
                                                        <article class="comment-body bg-light">
                                                            <footer class="comment-meta">
                                                                <div class="comment-author ">
                                                                    <img alt="" src="assets/img/team/t-2.jpg" class="">
                                                                    <b class="fn">
                                                                <span class="text-success">
                                                                    <?php echo $cm_row['name_family']; ?>
                                                                </span>
                                                                    </b>
                                                                </div><!-- .comment-author -->

                                                                <div class="comment-metadata">
                                                                    <small>
                                                                        <?php echo "<badge class='badge-pill badge-success'>تاریخ " $cm_row['cdate'] . " در ساعت " $cm_row['ctime'] . "</badge>"?>
                                                                    </small>
                                                                </div><!-- .comment-metadata -->

                                                            </footer><!-- .comment-meta -->

                                                            <div class="comment-content">
                                                                <?php echo nl2br($cm_row['comment']); ?>
                                                            </div><!-- .comment-content -->


                                                        </article><!-- .comment-body -->
                                                    </li><!-- #comment-## -->
                                                </ul><!-- .children -->
                                            <?php endif; ?>


                                        </li><!-- #comment-## -->
                                    <?php endwhile; ?>

                                </ul>
                            </div>
                            <!--comments area end-->
                        </div>

                        <?php } else echo "    <div class=\"alert alert-primary\" style=\"text-align: center\">تابحال نظری برای این پست ثبت نشده ، شما اولین نفر باشید :)</div>
"
;
 
                       ?>


                        <?php include_once "pages/comments.php"?>
                    </div>
                </div> 


فایل‌های پیوست تصاویر بندانگشتی
   
  پاسخ
تشکر شده توسط : ریموت پارکینگ
#2
سلام
متوجه نشدم چی نوشتین ولی به جای اینکه توضیح بدم خوبتر و بهتر اینه comment and replay in phpرو جستجو کنید نتایج بهتر از توضیح من گیرتون میاد
  پاسخ
تشکر شده توسط : Master_Power
#3
مشکلم حل شد
باید برای کامنت ها 2 تا جدول جداگانه میساختم
من اشتباهم این بود که یک جدول ساخته بودم و comment_parrent_id را هم توی همون یه جدول گذاشته بودم
با ساخت 2 جدول جداگانه و تفکیک کامنت ها مشکل حل شد
  پاسخ
تشکر شده توسط :


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان