前端獲取數據: thinkphp讀取資料庫數據: ...
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();
}
前端獲取數據:
<td style="width:85%;padding-left:15px;line-height:30px;"> {$new.detail}...... </td>
thinkphp讀取資料庫數據:
<?php //讀取一行數據 $user=M("user"); $data=$user->where("status=1 AND name="thinkphp"")->find(); dump($data); //讀取數據集合 $User=M("user"); $list = $user->where('status=1')->order("create_time")->limit(10)->select(); //讀取欄位值 $user=M("user"); $nickname=$user->where("id=3")->getFild('nickname'); //如果傳入多個欄位 $user=M("user"); $list=$user->getFild('id,nickname'); //兩個欄位的情況下返回的是array(`id`=>`nickname`)的關聯數組,以id的值為key,nickname欄位值為value。