Reputation: 3755
Controller
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);
Model
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
The problem i'm facing is not being able to limit the amount of result returned because for this "HIGH" $type , there isnt any setting build in. For the other $type there is a setting at admin panel with a number of how many to return. Is there anyway i can insert a LIMIT number here to force it to return a fix amount of result?
Upvotes: 0
Views: 82
Reputation: 15981
Your method has a fourth parameter to pass custom limit but it is array so pass as below
//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);
Upvotes: 2