mysqli_fetch_assoc没有显示所有结果

I cannot figure out why mysqli_fetch_assoc shows only one result instead of five. I doubled checked the database and there are 5 entries for sure..

In the case if I remove second mysqli_fetch_assoc then shown are all results.

Please note: connection include is above..

Any advice and suggestions will be greatly appreciated... Thank you!

<table class="table table-bordered table-hover">
    thead>
         <tr>
            <th>Id</th>
            <th>Author</th>
            <th>Title</th>
            <th>Category</th>
            <th>Status</th>
            <th>Image</th>
            <th>Tags</th>
            <th>Comments</th>
            <th>Date</th>
        </tr>
 </thead>
       <tbody>
            <?php 
               if(isset($_GET['delete'])){
                     $post_id = $_GET['delete'];   
                     $query = "DELETE FROM posts  WHERE post_id='$post_id'";
                     $delete_post_query = mysqli_query($con, $query);

            }
               $query = mysqli_query($con, "SELECT * FROM posts");
           while($row = mysqli_fetch_assoc($query)) {
                     $post_id = $row['post_id'];
                     $post_category_id = $row['post_category_id']; 
                     $post_title = $row['post_title']; 
                     $post_author = $row['post_author'];
                     $post_status = $row['post_status'];
                     $post_image = $row['post_image'];
                     $post_content = $row['post_content'];
                     $post_tags = $row['post_tags'];
                     $post_comment_count = $row['post_comment_count'];
                     $post_date = $row['post_date'];


                                    echo "<tr>";
                                    echo "<td>$post_id</td>";
                                    echo "<td>$post_author</td>";
                                    echo "<td>$post_title</td>";

                                $query = mysqli_query($con, "SELECT * FROM categories WHERE cat_id='$post_category_id'");

                                while($row = mysqli_fetch_assoc($query)) {

                                    $cat_id = $row['cat_id'];    
                                    $cat_title = $row['cat_title'];

                                    echo "<td>$cat_title</td>";

                                }

                                    echo "<td>$post_status</td>";
                                    echo "<td><img src='../images/$post_image' alt='image' width='100'></td>";
                                    echo "<td>$post_tags</td>";
                                    echo "<td>$post_comment_count</td>";
                                    echo "<td>$post_date</td>";
                                    echo "<td><a href='posts.php?delete=$post_id'>Delete</a></td>";
                                    echo "<td><a href='posts.php?source=edit_post&p_id=$post_id'>Edit</a></td>";
                                    echo "</tr>";

                                }

                                ?>

                            </tr>
                        </tbody>
                    </table>

You are nesting database queries and are reusing the same variable names.

The first time around the loop you make the nested query and overwrite your $query variable.

You finish your inner loop and then try to read the next item from the inner loops query (which you just finished looping over).

Don't recycle variable names.

Also consider using JOINs instead of multiple queries.