thinkphp資料的查詢和截取

來源:互聯網
上載者:User

標籤:pre   img   數組   lis   讀取   name   返回   select   field   

    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。

 

thinkphp資料的查詢和截取

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.