• 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="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。
  • 相关阅读:
    图论
    后缀数组专题
    AC自动机
    线段树·二
    nginx实现负载均衡
    关于mysql binlog二进制
    linux下每次git clone无需多次输入账号密码
    Centos7 yum安装 MySQL5.7.25
    docker基本操作和部署
    composer update 或者 composer install提示killed解决办法
  • 原文地址:https://www.cnblogs.com/yangzailu/p/6258771.html
Copyright © 2020-2023  润新知