Home  >  Q&A  >  body text

When querying paging in a closure, the paging conditions for printing SQL are not attached. By default, all are displayed.

Why can the teacher write it directly and use it? When I tested it, everything was displayed. The paging conditions were ignored directly. When printing the sql, it showed that there were no paging conditions.

年年年年年年年年年年2054 days ago1326

reply all(5)I'll reply

  • 尾生

    尾生2019-03-29 09:17:46

    Just change the position of that code:

    public function index()
    {
    //Category information display
    $cateId=Request::param('cate_id') : >assign('cateName',$res->name);
            $artList=Db::name('zh_article')
                                                                                                                                                         ;where('cate_id',$cateId)
                                                                                                                                                                                                                                                            through ',$artList);
    }
    else{
    $artList=Db::name('zh_article')
    ->order('create_time','desc')->paginate(3);
    $this->view->assign('cateName','All articles');
    }
    $this->view->assign('artList',$artList);

    return $this->fetch();
    }

    reply
    0
  • 尾生

    尾生2019-03-27 22:46:52

    抱歉,应该是这样的:

    if (isset($cateId))
    {
       $artList=Db::table('zh_article')
           ->where('status',1)
           ->where('cate_id',$cateId)
           ->order('create_time','desc')->paginate(3);



    }
    $artList=Db::table('zh_article')
       ->where('status',1)
       ->where('cate_id',$cateId)
       ->order('create_time','desc')->paginate(3);


    $this->view->assign('artList',$artList);

        return $this->fetch();


    reply
    0
  • 尾生

    尾生2019-03-27 22:44:21

    if (isset($cateId))
    {
       $artList=Db::table('zh_article')
           ->where('status',1)
           ->where('cate_id',$cateId)
           ->order('create_time','desc')->paginate(3);



    }
    $artList=Db::table('zh_article')
       ->where('status',1)

       ->order('create_time','desc')->paginate(3);


    $this->view->assign('artList',$artList);

        return $this->fetch();

    这样子可以出来

    reply
    0
  • 永~不~低~头

    永~不~低~头2019-03-24 14:22:37

    The same question

    reply
    0
  • Cancelreply