我该如何处理在不同的岗位,个人意见?

问题描述 投票:0回答:2

我希望能够单独获得每个岗位,但它好像我只获得了第一个。 是不是有一种方法,我可以使用PHP唯一识别每一个职位,然后我访问使用javascript相同的值?

或任何其他解决方案如何我可以处理在不同的岗位多条评论。它的每一样东西还有刚刚工作的罚款。

let otherCommentForms = document.querySelectorAll('.postComments');

otherCommentForms.forEach((otherComment) => {
     otherComment.addEventListener('submit', (e)=>{
        e.preventDefault();
        // let post_id = $('#post_id_other').val();
        let post_id = $(this).find('input#post_id_other').val();
        // let userComment = $('#userCommentAreaOther').val();
        let userComment = $(this).find('input#userCommentAreaOther').val();
        // e.preventDefault();
        console.log(`Post Identification: ${post_id} Comment: ${userComment}`);
        console.log(`User Comment: ${userComment}`);
        // $.post(serverScript, {
            // comment: userComment,
            // post_id: post_id
        //  }, function (data) {
            //       $("#theCommentsOther").html(data);
                     $(this).find('input#userCommentAreaOther').val('');
            // });
        });
    });

下面是HTML代码:

<?php
    $post_set = getPosts();
    while ($post = mysqli_fetch_assoc($post_set)) {?>
        <div class="central-meta item">
            <div class="user-post">
                <div class="friend-info">
                    <div class="friend-name">
                       <ins><a title=""><?php echo $post['headline']?></a></ins>
                    </div>
                    <div class="post-meta">
                        <img src="<?echo "PostImages/".$post['imageName']?>" alt="">
                       <div class="description">
                         <p><?php echo $post['caption'] ?></p>
                        </div>
                    </div>
                </div>
                <!-- friend-info -->

                <ul class="we-comet">
                    <li class="post-comment">
                        <div class="post-comt-box">
                        <!-- comment form action to be removed  -->
                         <form method="post" action="" class="postComments">
                          <input type="hidden" name="post_id" value="<?php echo $post['id']?>" id="post_id_other">
                          <!-- <textarea placeholder="Post your comment" name="comment" id="userComment" required></textarea> -->
                          <input type="text" name="comment" id="userCommentAreaOther" placeholder="Post your comment" class="form-control" required>
                          <input type="submit" value="Comment" class="mtr-btn signup" style="background:#4f93ce; color:white; border:#4f93ce;">
                         </form>
                        </div>
                    </li>

                    <div id="theCommentsOther">
                        <?php 
                            $comment_set = find_comments($post['id']);
                            while ($comment_ind = mysqli_fetch_assoc($comment_set) ) {?>
                             <li style="display: inline-block;  margin-bottom: 20px; width: 100%;">
                             <div class="we-comment">
                                <div class="coment-head">
                                    <h5><?php  echo userName($comment_ind['user_id']);?></h5>
                                </div>
                                <p><?php echo $comment_ind['content']?></p>
                             </div>
                             </li>
                            <?php }?>
                        </div>
                       <!-- where the comments are fed using ajax -->
                    </ul>
                </div><!-- Userpost -->
            </div><!-- central-meta -->
        <?php } ?>
javascript php jquery
2个回答
0
投票

每种形式的ID在你复制的循环检查。


0
投票

你对你的HTML循环相同的ID,尝试使用一个唯一的ID

© www.soinside.com 2019 - 2024. All rights reserved.