关于thinkphp查询以及分页的有关问题
程序员文章站
2022-04-18 22:39:23
...
关于thinkphp查询以及分页的问题
控制器里面的search方法:
列表页的代码:
控制器里面的search方法:
public function search(){
import("@.ORG.Page");
$list = D('Blog');
$keyword = trim($this->_post('keyword','htmlspecialchars'));
$sql = "SELECT b.*, a.`content`, u.`username`
FROM blog b
LEFT JOIN blog_attribute a ON a.`blog_id`=b.`id`
LEFT JOIN user u ON u.`id`=b.`user_id`
";
if(!empty($keyword)){
$sql .= " WHERE b.`title` LIKE '%{$keyword}%' OR a.`content` LIKE '%{$keyword}%'";
}
$count = count($list->query($sql));
$Page = new Page($count,2);
$firstRow = $Page->firstRow;
$listRows = $Page->listRows;
$this->data = $list->searchBlog($sql,$firstRow,$listRows);
$xxx['data'] = $this->data;
$page = $Page->show();
$xxx['page'] = $page;
//$this->data['page'] = $page;
//$this->assign("page",$page);
//var_dump(urldecode(json_encode($this->data)));
$this->show(urldecode(json_encode($xxx)));
}
列表页的代码:
上一篇: 选择什么PHP框架