1、分类求和
public function find()
{
//$data['oders'] = $this->db->table('oders')->order('need_time')->lists();
//$data['oders']= $this->db->table('oders')->field('name,SUM(price) AS prices')->group('name')->lists();
$data['oders']= $this->db->table('store')->field('name,SUM(qty) AS qtys')->group('name')->products();
dump( $data['oders']);
exit();
$this->assign('data', $data);
return $this->fetch();
}
//$products = $this->db->table('product')->field('name,SUM(price) AS prices')->group('name')->select();
public function products(){
$products = Db::name($this->table)->field($this->field)->group($this->group)->select();
return $products ? $products : false;
}
2、session
$admin = $this->db->table('admins')->where(array('username'=>$username))->item();
session('admin',$admin);
<div class="header">
<span class="title"><span style="font-size: 12px;">{$site.values}</span>-后台管理系统</span>
<span class="userinfo">{$admin.username}{$admin.truename}【{$role.title}】<span><a href="javascript:;" ="logout()">退出</a></span></span>
</div>
3、查询
传空值调用视图Post提交 查询调用视图显示
public function outfind()
{
$this->assign('data', '');
return $this->fetch();
}
4、7种jion连接之入库
$sql="SELECT *, a.name FROM (select * from oders where need_time = :time ) a LEFT JOIN (select store_time, name from store group by name) b ON a.name = b.name and a.need_time = b.store_time where store_time is null ";
$data['price']=Db::query($sql,['time'=>date('Y-m-d') ]);
dump($data['price']);