tp分页

tp5 分页

动态举报管理
-
查询 重置
<?php if($user_info){ ?> {foreach $user_info as $user_row}
数据列表
选项发布者ID发布者昵称发布地区文字内容举报次数发布时间操作
{$user_row.mem_id}{$user_row.nickname}{$user_row.city}{$user_row.content|substr=0,40}{$user_row.report_count}{$user_row.create_time}
详情 删除 {/if}
            </div>
          </td>
        </tr>
        {/foreach}
        <?php } ?>
        </tbody>
        <tfoot>
        <th colspan="11">
          <span id="checkall" checked><input type="checkbox" class="layui-btn" ></span>全选
          <div class="layui-input-inline" id="acut">
            <select name="num">
              <option value="">批量操作</option>
              <option value="2" >删除</option>
            </select>
          </div>
          <button  id='batch_btn' class="layui-btn" >
            确定
          </button>
        </th>
        </tfoot>
      </table>
    </div>
  </div>
</div>
<?php /** * Created by PhpStorm. * User: zeng152330 * Date: 2018/12/3 * Time: 16:01 */ namespace app\admin\controller; use think\Db; class ReportController extends BaseController { /** * 动态列表 * @param int $page * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function dynamicList($page = 1) { if ($page < 1) { $page = 1; } $mem_id = isset($_GET['mem_id']) ? $_GET['mem_id'] : ''; $name = isset($_GET['name']) ? $_GET['name'] : ''; $start_time = isset($_GET['start_time']) ? $_GET['start_time']: ''; $end_time = isset($_GET['end_time']) ? $_GET['end_time'] : ''; $where = []; if ($mem_id != '') { $where['m.id'] = ['=', $mem_id]; } if ($name != '') { $where['m.nickname'] = ['like', '%' . $name . '%']; } if ($start_time != '' && $end_time != '') { $tmp1 = strtotime(date('Y-m-d 00:00:00',strtotime($start_time))); $tmp2 = strtotime(date('Y-m-d 23:59:59',strtotime($end_time))); $where['p.create_time'] = ['BETWEEN', [$tmp1, $tmp2]]; } elseif ($start_time == '' && $end_time != '') { $tmp2 = strtotime(date('Y-m-d 23:59:59',strtotime($end_time))); $where['p.create_time'] = ['<', $tmp2]; } elseif ($end_time == '' && $start_time != '') { $tmp1 = strtotime(date('Y-m-d 00:00:00',strtotime($start_time))); $where['p.create_time'] = ['>', $tmp1]; } $offset = 10; $count = Db::name('report r') ->join('publication p','r.content_id = p.id') ->join('member m','m.id=p.mem_id') ->where($where) ->where('r.report_type=1') ->count('distinct(p.id)'); $pages = ceil($count / $offset); $pre = ($page - 1) * $offset; $sql = "select count(re.id) from t_report re where re.content_id =p.id and re.report_type=1 "; $ids = Db::name('report r') ->join('publication p','r.content_id = p.id') ->join('member m','m.id=p.mem_id') ->distinct(true) ->field('p.id') ->where($where) ->where('r.report_type=1') ->select(); if (count($ids) > 0) { $arr = array_column($ids,'id'); $id = implode(',',$arr); } else { $id =0; } $user_info = Db::name('member m,t_publication p') ->field("m.id as mem_id,m.nickname,p.id,p.city,p.content,p.create_time,({$sql}) as report_count") ->where($where) ->where("m.id=p.mem_id and p.id in ($id)") ->order('report_count desc') ->limit($pre, $offset) ->select(); if (count($user_info) > 0) { foreach ($user_info as $key=>$value) { $user_info[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']); } } $this->assign('pages', $pages); $this->assign('count', $count); $this->assign('user_info', $user_info); $this->assign([ 'page' => $page, 'count' => $count, 'search_id' =>$mem_id, 'search_name' => $name, 'search_start_time' => $start_time, 'search_end_time' => $end_time, ]); return $this->fetch(); } /** * Notes:动态举报详情 * Auther: 秦汉 * Date: 2018/12/7 * @param $id * @param int $page * @return mixed */ public function reportDynamicList($id, $page = 1) { if ($page < 1) { $page = 1; } $mem_id = input('post.id'); $offset = 5; $count = Db::name('report') ->where(['content_id' => $id,'report_type' => 1]) ->count("id"); $pages = ceil($count / $offset); $pre = ($page - 1) * $offset; $info = Db::name('report r, t_member m') ->field("m.nickname,m.mobile,m.head_pic,r.id,r.report_style,r.report_time,r.reason") ->where(" r.content_id= {$id} and r.report_type=1 and r.report_userid = m.id") ->order('r.report_time desc') ->limit($pre, $offset) ->select(); if (count($info) > 0) { foreach ($info as $key => $value) { $info[$key]['head_pic'] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$value['head_pic']; } } $this->assign('id', $id); $this->assign('pages', $pages); $this->assign('count', $count); $this->assign('info', $info); $this->assign([ 'page' => $page, 'count' => $count, ]); return $this->fetch(); } /** *删除动态 */ public function delDynamic() { $publication_id = input('post.id'); //删除我的动态 同时删除相关的评论,相关的点赞,相关的举报,相关的收藏 Db::startTrans(); try{ Db::name('publication')->delete([$publication_id]); Db::name('publication_comment')->where(['publication_id'=>['in',$publication_id]])->delete(); Db::name('publication_point')->where(['publication_id'=>['in',$publication_id]])->delete(); Db::name('publication_collect')->where(['publication_id'=>['in',$publication_id]])->delete(); Db::name('report')->where(['content_id'=>['in',$publication_id],'report_type'=>1])->delete(); Db::commit(); return 1; }catch (\Exception $e) { // 回滚事务 Db::rollback(); return 0; } } /** * 批量删除动态 * @return int * @throws \think\Exception * @throws \think\exception\PDOException */ public function batchDynamic() { $arr = input('post.'); $ids = implode(',', $arr['arr']); Db::name('publication')->delete($ids); Db::name('publication_comment')->where(['publication_id'=>['in',$ids]])->delete(); Db::name('publication_point')->where(['publication_id'=>['in',$ids]])->delete(); Db::name('publication_collect')->where(['publication_id'=>['in',$ids]])->delete(); Db::name('report')->where(['content_id'=>['in',$ids],'report_type'=>1])->delete(); return 0; } /** * 动态详情 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function dynamicInfo($id = '') { $info = Db::name('member m,t_publication p') ->field("m.nickname,m.head_pic,p.id,p.city,p.content,p.filename,p.create_time") ->where("m.id=p.mem_id and p.id=$id") ->find(); $info['head_pic'] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$info['head_pic']; $info['create_time'] = date('Y-m-d H:i:s', $info['create_time']); $point_total = Db::name('publication_point')->where('publication_id',$id)->count('id'); $info['point_count'] = $point_total; if (!empty($info['filename'])) { $array =explode(';', $info['filename']); foreach ($array as $key => $value) { $array[$key] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$value; } $info['filename'] = $array; } $comments = $this->comment($id); $count = Db::name('publication_comment t') ->join('member m','t.form_userid=m.id','left') ->where('t.publication_id',$id) ->count('t.id'); $page = 1; $this->assign('info', $info); $this->assign('count', $count); $this->assign('page', $page); $this->assign('id', $id); $this->assign('comments', $comments); return $this->fetch(); } /** * 查询评论 * @param int $id * @param int $pre * @param int $offset * @return false|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function comment($id, $pre = 0, $offset = 5) { $comments = Db::name('publication_comment t') ->join('member m','t.form_userid=m.id','left') ->field("m.nickname,m.head_pic,t.id ,t.publication_id,t.form_userid,t.to_userid,t.content,t.create_time,t.status,t.comment_type") ->where('t.publication_id',$id) ->order('t.create_time desc') ->limit($pre, $offset) ->select(); if(count($comments) > 0) { foreach ($comments as $key => $val) { $comments[$key]['create_time'] = date('Y-m-d H:i:s'); $comments[$key]['head_pic'] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$val['head_pic']; } } return $comments; } /** * 评论翻页 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function comPage() { $id = isset($_POST['id']) ? $_POST['id'] : ''; $page = isset($_POST['page']) ? $_POST['page'] : ''; $pre = ($page - 1) * 5; $com_page = $this->comment($id, $pre); $con_html = $this->comHtml($com_page); return $con_html; } /** * 评论页面 * @param $com * @return string */ public function comHtml($com) { $html_str = ''; foreach ($com as $key => $value) { $html_str .= '
'; $html_str .= '
'; $html_str .= '
'; $html_str .= ' ' . $value['nickname'] . ''; $html_str .= '' . $value['create_time'] . ''; $html_str .= ''; $html_str .= ''; $html_str .= '
'; $html_str .= '
' . $value['content'] . '
'; $html_str .= '
'; $html_str .= '
'; } return $html_str; } /** * 删除评论 * @return int * @throws \think\Exception * @throws \think\exception\PDOException */ public function delComments() { $id = input('post.com_id'); //删除我的动态 同时删除相关的评论,相关的点赞,相关的举报,相关的收藏 Db::startTrans(); try{ Db::name('publication_comment')->where(['id'=>$id])->delete(); Db::name('report')->where(['content_id'=>$id,'report_type'=>2])->delete(); Db::commit(); return 1; }catch (\Exception $e) { // 回滚事务 Db::rollback(); return 0; } } /** * 评论详情 * @param int $page * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function commentList($page = 1) { if ($page < 1) { $page = 1; } $mem_id = isset($_GET['mem_id']) ? $_GET['mem_id'] : ''; $name = isset($_GET['name']) ? $_GET['name'] : ''; $start_time = isset($_GET['start_time']) ? $_GET['start_time']: ''; $end_time = isset($_GET['end_time']) ? $_GET['end_time'] : ''; $where = []; if ($mem_id != '') { $where['m.id'] = ['=', $mem_id]; } if ($name != '') { $where['m.nickname'] = ['like', '%' . $name . '%']; } if ($start_time != '' && $end_time != '') { $tmp1 = strtotime(date('Y-m-d 00:00:00',strtotime($start_time))); $tmp2 = strtotime(date('Y-m-d 23:59:59',strtotime($end_time))); $where['p.create_time'] = ['BETWEEN', [$tmp1, $tmp2]]; } elseif ($start_time == '' && $end_time != '') { $tmp2 = strtotime(date('Y-m-d 23:59:59',strtotime($end_time))); $where['p.create_time'] = ['<', $tmp2]; } elseif ($end_time == '' && $start_time != '') { $tmp1 = strtotime(date('Y-m-d 00:00:00',strtotime($start_time))); $where['p.create_time'] = ['>', $tmp1]; } $offset = 10; $count = Db::name('report r') ->join('publication_comment p','r.content_id = p.id') ->join('member m','m.id=p.form_userid') ->where($where) ->where('r.report_type=2') ->count('distinct(p.id)'); $pages = ceil($count / $offset); $pre = ($page - 1) * $offset; $sql = "select count(re.id) from t_report re where re.content_id =p.id and re.report_type=2 "; $ids = Db::name('report r') ->join('publication_comment p','r.content_id = p.id') ->join('member m','m.id=p.form_userid') ->distinct(true) ->field('p.id') ->where($where) ->where('r.report_type=2') ->select(); if (count($ids) > 0) { $arr = array_column($ids,'id'); $id = implode(',',$arr); } else { $id =0; } $user_info = Db::name('member m,t_publication_comment p') ->field("m.id as mem_id,m.nickname,p.id,p.content,p.create_time,({$sql}) as report_count") ->where($where) ->where("m.id=p.form_userid and p.id in ($id)") ->order('report_count desc') ->limit($pre, $offset) ->select(); if (count($user_info) > 0) { foreach ($user_info as $key=>$value) { $user_info[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']); } } $this->assign('pages', $pages); $this->assign('count', $count); $this->assign('user_info', $user_info); $this->assign([ 'page' => $page, 'count' => $count, 'search_id' =>$mem_id, 'search_name' => $name, 'search_start_time' => $start_time, 'search_end_time' => $end_time, ]); return $this->fetch(); } /** * Notes: 评论举报 * Auther: 秦汉 * Date: 2018/12/7 * @param $id * @param int $page * @return mixed */ public function reportCommentList($id, $page = 1) { if ($page < 1) { $page = 1; } $mem_id = input('post.id'); $offset = 5; $count = Db::name('report') ->where(['content_id' => $id,'report_type' => 2]) ->count("id"); $pages = ceil($count / $offset); $pre = ($page - 1) * $offset; $info = Db::name('report r, t_member m') ->field("m.nickname,m.mobile,m.head_pic,r.id,r.report_style,r.report_time,r.reason") ->where(" r.content_id= {$id} and r.report_type=2 and r.report_userid = m.id") ->order('r.report_time desc') ->limit($pre, $offset) ->select(); if (count($info) > 0) { foreach ($info as $key => $value) { $info[$key]['head_pic'] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$value['head_pic']; } } $this->assign('id', $id); $this->assign('pages', $pages); $this->assign('count', $count); $this->assign('info', $info); $this->assign([ 'page' => $page, 'count' => $count, ]); return $this->fetch(); } /** * 动态详情 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function commentInfo($id = '') { $publication_id = Db::name('publication_comment')->where('id',$id)->value('publication_id'); $info = Db::name('member m,t_publication p') ->field("m.nickname,m.head_pic,p.id,p.city,p.content,p.filename,p.create_time") ->where("m.id=p.mem_id and p.id=$publication_id ") ->find(); $info['head_pic'] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$info['head_pic']; $info['create_time'] = date('Y-m-d H:i:s', $info['create_time']); $point_total = Db::name('publication_point')->where('publication_id',$publication_id)->count('id'); $info['point_count'] = $point_total; if (!empty($info['filename'])) { $array =explode(';', $info['filename']); foreach ($array as $key => $value) { $array[$key] = 'http://'.$_SERVER['HTTP_HOST'].uploadName().$value; } $info['filename'] = $array; } $comments = $this->comment($id); $count = Db::name('publication_comment t') ->join('member m','t.form_userid=m.id','left') ->where('t.publication_id',$id) ->count('t.id'); $page = 1; $this->assign('info', $info); $this->assign('count', $count); $this->assign('page', $page); $this->assign('id', $id); $this->assign('comments', $comments); return $this->fetch(); } /** *删除评价 */ public function delComment() { $comment_id = input('post.id'); //删除我的动态 同时删除相关的评论,相关的点赞,相关的举报,相关的收藏 Db::startTrans(); try{ Db::name('publication_comment')->where(['id'=>['in',$comment_id]])->delete(); Db::name('report')->where(['content_id'=>['in',$comment_id],'report_type'=>2])->delete(); Db::commit(); return 1; }catch (\Exception $e) { // 回滚事务 Db::rollback(); return 0; } } /** * 批量删除动态 * @return int * @throws \think\Exception * @throws \think\exception\PDOException */ public function batchComment() { $arr = input('post.'); $ids = implode(',', $arr['arr']); Db::name('publication_comment')->where(['id'=>['in',$ids]])->delete(); Db::name('report')->where(['content_id'=>['in',$ids],'report_type'=>2])->delete(); return 0; } }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TP3.2 是一个基于PHP的开源框架,它提供了很多方便的功能,其中包括利用jQuery Ajax实现分页功能。下面是一个例子说明如何使用jQuery Ajax实现前台与后台的分页功能: 前台源码: ```html <!DOCTYPE html> <html> <head> <title>分页示例</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ var currentPage = 1; // 当前页码 // 加载数据函数 function loadData(page){ $.ajax({ url: 'loadData.php', type: 'POST', data: {page: page}, success: function(response){ $("#dataContainer").html(response); } }); } // 初始加载数据 loadData(currentPage); // 点击页面切换按钮 $(document).on("click", ".pagination a", function(e){ e.preventDefault(); var page = $(this).attr("data-page"); currentPage = page; loadData(currentPage); }); }); </script> </head> <body> <div id="dataContainer"></div> </body> </html> ``` 后台源码(loadData.php): ```php <?php include "dbconfig.php"; // 引入数据库配置文件 $page = $_POST['page']; $perPage = 10; // 每页显示记录数 $offset = ($page - 1) * $perPage; // 计算偏移量 $result = $conn->query("SELECT * FROM your_table LIMIT $offset, $perPage"); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { echo "<p>{$row['name']}</p>"; } } $conn->close(); ?> ``` 上述代码中,前台页面加载时会发送一个Ajax请求到后台的`loadData.php`文件,同时传递一个`page`参数表示当前页码。后台根据参数查询对应的数据,并将结果返回给前台,然后前台更新页面内容。用户可以通过点击页面切换按钮,改变`page`参数的值,从而实现翻页功能。 需要注意,后台代码中的`dbconfig.php`文件应该包含数据库连接的配置信息,以确保能够成功连接数据库并查询数据。 这只是一个简单的分页功能示例,你可以根据自己的实际情况进行调整和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值