通过单击表列中的userid我想使用php控制器进行asc或desc的操作吗?
在控制器中
if(isset($_GET['sortOrder'])){
$reverse = ($_GET['sortOrder'] == 'desc') ? 'desc' : 'asc';
$okdata = DB::table('adminblogs')->orderBy('user_id', $reverse)->get();
return view("adminblog.index")->with("adminblogs", $okdata);
}
视图中
<table id="example" class="table table-bordered">
<thead> <tr>
<th>ID</th>
<th>TITLE</th>
<th><a id="sort" href="{{url('admin?sortOrder=asc')}}">USER ID</a></th>
<th>DELETE</th>
</tr>
</thead>
<tbody>
@foreach($adminblogs as $blog)
<tr>
<td>{{ $blog->id }}</td>
<td>{{ $blog->title }}</td>
<td>{{ $blog->user_id }}</td>
<td>
@if(Auth::id() == $blog->user_id)
<a href="{{ url('admin/destroy/'.$blog->id.'/'.$blog->user_id) }}" class="btn btn-danger" >DELETE</a>
@else
<a href="{{ url('admin/destroy/'.$blog->id.'/'.$blog->user_id) }}" class="disabled btn btn-danger" >DELETE</a>
@endif
</td>
</tr>
@endforeach
答案 0 :(得分:0)
只需像下面那样更改thead
<thead>
<tr>
<th>ID</th>
<th>TITLE</th>
<th><a id="sort" href="{{url('admin?sortOrder='.($_GET['sortOrder'] == 'desc') ? 'asc' : 'desc')}}">USER ID</a></th>
<th>DELETE</th>
</tr>
</thead>
<tbody>
答案 1 :(得分:0)
在有大量记录的情况下,数据表失败,因为那样一来,您必须在客户端获取所有集合