CodeIgniter method to get requests for superiors to approve
I am able to remove one for loop in my code with the following:

I changed my method in the Controller

public function process()
{
    $data = new stdClass;
    $data-&gt;param_menu = 'request';

    $staffInfo = $this-&gt;staffinfo_model-&gt;selectItem(array('member_idx'=&gt;$this-&gt;session-&gt;userdata('member_index')));

    $requests = $this-&gt;staffrequisition_model-&gt;getRequestsToProcess($staffInfo-&gt;position_depth,$staffInfo-&gt;department_group);

    foreach ($requests as &amp;$item) {
        for ($y = 1; $y &lt;=5 ; $y++) {
            if ($item-&gt;{'line'.$y.'_action'}!=='PENDING' &amp;&amp; $item-&gt;{'line'.$y.'_action'}!==''){
                $item-&gt;is_checked = TRUE;
                break;
            } else {
                $item-&gt;is_checked = FALSE;
            }
        }
    }

    $data-&gt;param_requests = $requests;

    $this-&gt;load-&gt;view('dashboard/staff/process_view', $data);
}


I changed my method in the Model

public function getRequestsToProcess($depth,$departmentGroup)
{
    $this-&gt;db-&gt;select('*, ns_request_info.idx as request_idx, ns_staff_info.idx as staff_idx');    
    $this-&gt;db-&gt;from('ns_request_info');
    $this-&gt;db-&gt;join('ns_staff_info', 'ns_request_info.requested_by_idx = ns_staff_info.member_idx');
    $this-&gt;db-&gt;where("((ns_request_info.line1=".$depth." AND ns_request_info.line1_action='PENDING') OR (ns_request_info.line2=".$depth." AND ns_request_info.line2_action='PENDING') OR (ns_request_info.line3=".$depth." AND ns_request_info.line3_action='PENDING') OR (ns_request_info.line4=".$depth." AND ns_request_info.line4_action='PENDING') OR (ns_request_info.line5=".$depth." AND ns_request_info.line5_action='PENDING'))");
    $this-&gt;db-&gt;where("(ns_request_info.status='PENDING' OR ns_request_info.status='ONGOING')");
    if($departmentGroup!='HIGHER TIER'){ $this-&gt;db-&gt;where('ns_staff_info.department_group', $departmentGroup); }
    $this-&gt;db-&gt;order_by('ns_request_info.idx', 'desc');
    $query = $this-&gt;db-&gt;get();
    return $query-&gt;result();
}


Now I dont have to loop my query five times. Instead I get it with just one query and loop through the result.