控制器
elseif($type == 'high'){
//Get Urgent Projects
$this->session->set_userdata('show_num','5');
$page_rows = $this->session->userdata('show_num');
$urgent_conditions = array('projects.project_status' => '0','budget_max >=' => '10');
$order = array('budget_max','DESC');
$this->outputData['listProjects'] = $this->skills_model->getProjects($urgent_conditions,NULL,NULL,NULL,$order);
$this->outputData['title'] = 'High Budget Projects';
$this->outputData['viewall'] = 'high_budget';
}
$this->load->view('listProjects',$this->outputData);
模型
function getProjects($conditions=array(),$fields='',$like=array(),$limit=array(),$orderby = array())
{
//Check For Conditions
if(is_array($conditions) and count($conditions)>0)
$this->db->where($conditions);
//Check For like statement
if(is_array($like) and count($like)>0)
$this->db->like($like);
//Check For Limit
if(is_array($limit))
{
if(count($limit)==1)
$this->db->limit($limit[0]);
else if(count($limit)==2)
$this->db->limit($limit[0],$limit[1]);
}
//pr($orderby);
//Check for Order by
if(is_array($orderby) and count($orderby)>0)
$this->db->order_by($orderby[0], $orderby[1]);
$this->db->from('projects');
$this->db->join('users', 'users.id = projects.creator_id','left');
//Check For Fields
if($fields!='')
$this->db->select($fields);
else
$this->db->select('projects.id,projects.project_name,projects.project_status,projects.description,projects.budget_min,projects.budget_max,projects.project_categories,projects.creator_id,projects.is_feature,projects.is_urgent,projects.is_hide_bids,projects.created,projects.attachment_name,projects.attachment_url,users.user_name,projects.enddate,projects.programmer_id,projects.project_award_date,projects.project_award_date,projects.contact,projects.salary,projects.flag,projects.escrow_due,users.id as userid,projects.checkstamp,projects.provider_rated,projects.buyer_rated,projects.project_paid,projects.is_private,projects.private_users,users.user_rating,users.num_reviews,users.email');
$result =$this->db->get();
return $result;
}//End of getProjects Function
我面临的问题是无法限制返回的结果数量,因为对于这个“HIGH”$类型,没有任何设置内置。对于其他$类型,管理面板上有一个设置返回的数量。无论如何我可以在这里插入LIMIT号码以强制它返回固定数量的结果吗?
答案 0 :(得分:2)
您的方法有第四个参数来传递自定义限制,但它是数组,因此传递如下
//this is limit 0,5
$this->skills_model->getProjects($urgent_conditions,NULL,NULL,array(5),$order);
//this is limit 5,20
$this->skills_model->getProjects($urgent_conditions,NULL,NULL,array(5,20),$order);