Query and intercept thinkphp data

Source: Internet
Author: User

Query and intercept thinkphp data

    public function NewsList(){        $this->assign('title','news');        $p = I('page',1);        $listRows = 6;        $News = M('news');        $info = $News->field('id,title,subtitle,publish_date,img,detail,typename')->where(array('type'=>'news','status'=>'1'))->order('flag desc,sort_no desc')->page($p,$listRows)->select();        if(!empty($info)){            foreach($info as $k=>$v){                $info[$k]['detail']=mb_substr($v['detail'],0,130,'utf-8');            }        }        $this->assign('news',$info);        $count = $News->where(array('type'=>'news','status'=>'1'))->count();        $Page = new Page($count,$listRows);        $show = $Page->show();        $this->assign('page',$show);        $this->display();    }

Frontend Data Acquisition:

<td style="width:85%;padding-left:15px;line-height:30px;">          {$new.detail}......</td>

 

Thinkphp reads database data:

<? Php // read a row of data $ user = M ("user"); $ data = $ user-> where ("status = 1 AND name =" thinkphp "") -> find (); dump ($ data); // read the data set $ User = M ("user "); $ list = $ user-> where ('status = 1')-> order ("create_time")-> limit (10)-> select (); // read the field value $ user = M ("user"); $ nickname = $ user-> where ("id = 3")-> getFild ('nickname '); // if multiple fields are input, $ user = M ("user"); $ list = $ user-> getFild ('Id, nickname '); // when two fields are returned, an associated array of array ('id' => 'nickname') is returned. The value of id is key and the value of nickname is v. Alue.

 

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.