/** * Ajax 请求分页 * @date 2015-01-13 * @return void */ public function getPageByAjax() { $modelTmp = M('sms_templates'); $pageCounts = $modelTmp->count(); // 总记录数 $pageSize = 10; // 每页数量,需要与index里面的方法保持一致 // Ajax分页类 $page = new \Think\AjaxPage($pageCounts, $pageSize); // 获取数据 $tmpArr = $modelTmp->limit($page->firstRow, $page->listRows)->select(); $string = ''; foreach ($tmpArr as $val) { $string .= '<tr>'; $string .= '<td style="text-align:center;">' . $val['id'] . '</td>'; $string .= '<td>' . $val['tmp_title'] . '</td>'; $string .= '<td style="text-align:center;">' . $val['tmp_no'] . '</td>'; $string .= '<td>' . $val['tmp_content'] . '</td>'; $string .= '<td style="text-align:center;">'; $string .= ' <a href="editTmp/id/' . $val['id'] . '"><i class="icon-pencil"></i> 编辑</a> | '; $string .= ' <a href="deleteTmp/id/' . $val['id'] . '" onclick="return confirm(\'您确定删除该模板吗?\');"><i class="icon-trash"></i> 删除</a>'; $string .= '</td>'; $string .= '</tr>'; $string .= '<tr>'; $string .= ' <td colspan="5">'; $string .= ' <div class="pagination alternate text-right" style="margin:0">'; $string .= $page->show(); $string .= ' </div> '; $string .= ' </td>'; $string .= '</tr>'; } $this->ajaxReturn($string); }
public function ajax_soso() { $title = trim(I('title', null)); $data['title'] = array('like', '%' . $title . '%'); $num = 12; //要求分页显示多少 $User = M('news'); // 实例化User对象 $count = $User->where($data)->count(); // 查询满足要求的总记录数 $Page = new \Think\AjaxPage($count, $num); // 实例化分页类 传入总记录数和每页显示的记录数 $list = $User->where($data)->order('id')->limit($Page->firstRow . ',' . $Page->listRows)->select(); if ($title != '') { //当输入关键词不为空 foreach ($list as $key => $value) { $row[] = array('id' => $value['id'], 'title' => preg_replace("/{$title}/", "<b style='color:red;'>" . $title . "</b>", $value['title'])); } } else { //当输入关键词为空时 foreach ($list as $key => $value) { $row[] = array('id' => $value['id'], 'title' => $value['title']); } } $show = $Page->show(); // 分页显示输出 $this->ajaxReturn(array('1' => $row, '2' => $show), JSON); }
public function quest() { if ($_POST["goodid"]) { $goodid = $_POST["goodid"]; $this->assign('goodid', $goodid); } session('goodid', null); //ajax评论session session('goodid', $goodid); $message = M("message"); $reply = M("reply"); $count = $message->where(" goodid='42'")->count(); $p = new \Think\AjaxPage($count, 5, "quest"); $limit = $p->firstRow . "," . $p->listRows; $page = $p->show(); $list = $message->where("goodid='42'")->order('id desc')->limit($limit)->select(); foreach ($list as $n => $val) { $list[$n]['id'] = $reply->where('messageid=\'' . $val['id'] . '\'')->select(); } $this->assign('list', $list); $this->assign('page', $page); $this->display(); }