php 数组分页
public function supplys($condition,$page,$count) { $ids = $this->getIds(); $qiu = $this->db->select("col.id AS coleid, a.title,a.addtime, c.name AS conpanyname ") ->from('hh_collection AS col') //求购 ->join('hh_asktobuy AS a','col.joinID = a.id','right') // 收藏 ->join('hh_company AS c','c.id = a.companyid','left') // 关联公司 ->where("a.id in($ids) AND $condition") ->get() ->result_array(); $gong = $this->db->select("col.id AS coleid, a.title,a.addtime, c.name AS conpanyname ") ->from('hh_collection AS col') //供应 ->join('hh_supply AS a','col.joinID = a.id','right') // 收藏 ->join('hh_company AS c','c.id = a.companyid','left') // 关联公司 ->where("a.id in($ids) AND $condition") ->get() ->result_array(); $list = array_merge($qiu, $gong); if($count){ return count($list); } // 数组分页 $count = count($list);//总条数 $start=($page-1)*5;//偏移量,当前页-1乘以每页显示条数 $list = array_slice($list,$start,5); foreach ($list as $k => $v){ $list[$k]['state'] = 0; } return $list; p($list); }
php数组分页主要就是 array_slice函数的使用
$count = count($list);//总条数 $start=($page-1)*5;//偏移量,当前页-1乘以每页显示条数 $list = array_slice($list,$start,5);