Thinkphp query and paging

Source: Internet
Author: User
About thinkphp query and paging problems the search method in the controller is public & nbsp; function & nbsp; search () {import ("@. ORG. page "); $ list & nbsp ;=& nbsp; D ('blog '); $ keyword & nbsp ;=& nbsp; t thinkphp query and paging problems
The search method in the controller:
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)));
}

Code on the list page:
 


$ (Document). ready (function (){
$ ("Button"). click (function (){
Var keyword = $ (this). parent ("div"). children ("input"). val ();
$. Ajax ({
Url: "{: U ('blog/Search ')}",
Type: "POST ",
Data: {"keyword": keyword },
Error: function (e ){
Alert ("query error! ");
},
Success: function (data ){
$ ("# Cell_tb_list"). empty ();
If (data! = ""){
Data = eval ('+ data + ')');
// Alert (data. data. length );
Var layer =" ";
Layer + ="";
Layer + =" ";
Layer + =" ";
Layer + =" ";
Layer + =" ";
Layer + =" ";
Layer + ="";
Layer + ="";
Layer + =" ";
Layer + =" Publisher";
Layer + =" Blog title";
Layer + =" Release Date";
Layer + =" Update Time";
Layer + =" Operation";
Layer + ="";
For (var I = 0; I
Layer + =" ";
Layer + =""+ Data. data [I]. username +"";
Layer + =""+ Data. data [I]. title +"";
Layer + =""+ Data. data [I]. create_time +"";
Layer + =""+ Data. data [I]. update_time +"";
Layer + ="Modify | delete";
Layer + ="";
}
Layer + =" "+ Data. page +"";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.