dongzhuohan7085 2019-05-09 07:09
浏览 57

通过使用mysql在php中单击asc或desc

By clicking on userid in the table column i want to asc or desc using php controller can it be done?

  1. IN CONTROLLER

          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);
          }
    
  2. IN VIEW

          <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
    
  • 写回答

2条回答 默认 最新

  • dougu2240 2019-05-09 08:00
    关注

    Just change the thead like below

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效