html:table不会为我的文章创建新行

0sgqnhkj  于 2021-06-25  发布在  Mysql
关注(0)|答案(3)|浏览(271)

我目前正在使用laravel从数据库中检索文章,并将它们逐个显示在表中。每一行将代表一个不同的职位。它应该工作,但我不知道是什么问题,它只创建2行。例如,一行是列标题,只有一行是所有文章的标题,而不是7行是7篇文章的标题。
以下是我在表格中显示帖子的代码:

<div class="container">
    <section class="row posts">
        <table class="post">
            <tr>
                <th>Title</th><th>Category</th><th>Description</th><th>Date Posted and Author</th>
            </tr>

            @foreach($posts as $post)
                <td>i</td> 
                <td>i</td> 
                <td>{{ $post->body }}</td>
                <td>Posted by {{ $post->user->first_name }} {{ $post->user->last_name }} on {{ $post->created_at }}</td>
            @endforeach
        </table>
    </section>
</div>

忽略前两列,我把'我',它只是一个占位符。

egdjgwm8

egdjgwm81#

你忘了 <tr> 在你的圈子里。试试这个。。

@foreach($posts as $post)
            <tr>
            <td>i</td> 
            <td>i</td> 
            <td>{{ $post->body }}</td>
            <td>Posted by {{ $post->user->first_name }} {{ $post->user->last_name }} on {{ $post->created_at }}</td>
            </tr>
        @endforeach
2nc8po8w

2nc8po8w2#

因为你没有使用 <tr> 标签

<div class="container">
    <section class="row posts">
        <table class="post">
            <tr>
                <th>Title</th><th>Category</th><th>Description</th><th>Date Posted and Author</th>
            </tr>

            @foreach($posts as $post)
                <tr>
                <td>i</td> 
                <td>i</td> 
                <td>{{ $post->body }}</td>
                <td>Posted by {{ $post->user->first_name }} {{ $post->user->last_name }} on {{ $post->created_at }}</td>
               </tr>
            @endforeach
        </table>
    </section>
</div>
snvhrwxg

snvhrwxg3#

<!--hope this works to create rows -->
<div class="container">
<section class="row posts">
    <table class="post">
        <tr>
            <th>Title</th><th>Category</th><th>Description</th>
             <th>Date Posted and Author</th>
        </tr>

        @foreach($posts as $post)
              <tr>
            <td>i</td> 
            <td>i</td> 
            <td>{{ $post->body }}</td>
            <td>Posted by {{ $post->user->first_name }} 
              {{ $post->user->last_name }} on 
              {{ $post->created_at }}</td></tr>
        @endforeach
    </table>enter code here
   </section>
    </div>

相关问题