控制器
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” $type ,没有任何设置内置。对于另一个 $type 在管理面板中有一个设置,其中包含一些如何许多人返回。无论如何我可以在这里插入一个 LIMIT 数字来强制它返回固定数量的结果吗?