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.