【问题标题】:How to add new row at the beginning of table instead of adding at the bottom?如何在表格的开头添加新行而不是在底部添加?
【发布时间】:2020-02-09 13:49:10
【问题描述】:

我想在表格的开头插入一个新行,但我不知道怎么做?

@foreach ($dbData as $newField)
<form action="{{url('/update')}}" method="POST">  //update the form
@csrf
<input type="hidden" name="id" value="{{$newField->id}}">
<tr>
<td class="column"> {{$i}}</td>
<td class="column"> {{$newField->task}}</td>   //make new column
<td class="column"> {{$newField->description}}</td>
<td>
<div class="form-check">
<input class="form-check-input" type="radio" name="status1" id={{$newField->id}} value="1" @if($newField->status == 1) checked @endif>
<label class="form-check-label" for={{$newField->id}}>
not started
</label>
</div>
<button type="submit">save</button>  //save form information to the table

【问题讨论】:

  • 在foreach中使用前先排序
  • 你为什么要这么做。请改用sortBy()
  • OrderBy('id','desc') 是您所需要的。它将在顶部获取最新数据。所以你不必在前端做任何排序。

标签: php html laravel phpmyadmin


【解决方案1】:

根据this 答案的第一个答案,表格没有开头或结尾(顶部或底部)。

而如果你想先获取最后插入的数据,你可以使用 SQL OrderBy 功能来实现。

这是 w3schools 的一个很好的资源
https://www.w3schools.com/sql/sql_orderby.asp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-12
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 2015-03-09
    • 1970-01-01
    相关资源
    最近更新 更多