انجمن ایران پی اچ پی
اصلاح حلقه کد - نسخه قابل چاپ

+- انجمن ایران پی اچ پی
+-- انجمن: پی اچ پی/PHP (https://forum.iranphp.org/Forum-%D9%BE%DB%8C-%D8%A7%DA%86-%D9%BE%DB%8C-PHP)
+--- انجمن: کدنویسی (https://forum.iranphp.org/Forum-%DA%A9%D8%AF%D9%86%D9%88%DB%8C%D8%B3%DB%8C)
--> +--- موضوع: اصلاح حلقه کد



اصلاح حلقه کد - Master_Power - ۱۳۹۸ خرداد ۲۷

سلام
یه کد برای بخش نظرات توشتم ولی هر پاسخی که کامنت ها میدم زیر کامنت کاربر نمی افته و همه ی پاسخ ها در پایین می افتن و کامنت کاربران همشون در بالا
میشه راهنمایی کنید ؟
تصویر قسمت کامنت ها را پیوست کردم ببینید چطوریه

فکر کنم مشکلم توی جایگزاری حلقه ها هست
کد پی‌اچ‌پی:
<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> 



RE: اصلاح حلقه کد - باز باران با ترانه - ۱۳۹۸ تير ۰۱

سلام
متوجه نشدم چی نوشتین ولی به جای اینکه توضیح بدم خوبتر و بهتر اینه comment and replay in phpرو جستجو کنید نتایج بهتر از توضیح من گیرتون میاد


RE: اصلاح حلقه کد - Master_Power - ۱۳۹۸ تير ۱۲

مشکلم حل شد
باید برای کامنت ها 2 تا جدول جداگانه میساختم
من اشتباهم این بود که یک جدول ساخته بودم و comment_parrent_id را هم توی همون یه جدول گذاشته بودم
با ساخت 2 جدول جداگانه و تفکیک کامنت ها مشکل حل شد