phpcodeignitermodel-view-controllerquery-builderresultset

How to pass a 2d result set from a controller to a view file in CodeIgniter


at library/comment.php

function getSelectedOneFieldJoin2TblGroupOrder($select, $table, $where, $join_table1, $join_condition1, $join_table2, $join_condition2, $order_by=null)
{
    $this->CI->db->select($select);
    $this->CI->db->from($table);
    
    $where2 = substr($where,6);
    $this->CI->db->where($where2);
          
        $this->CI->db->join($join_table1, $join_condition1, 'left');
        $this->CI->db->join($join_table2, $join_condition2, 'left');
            
    $this->CI->db->order_by($order_by);

    $query = $this->CI->db->get();
    $result = $query->row_array();

    if ($result) {
        return $result[$select];
    }
    
    return null; 
}

at controller/Dashboard.php

$res1=$this->common->getSelectedOneFieldJoin2TblGroupOrder(
" 'Product Order Placed' as activity_title, u.created_on as created_on, m.first_name AS created_by",
"tbl_product_order u",
"WHERE u.status != 2 and u.status != 0",
"tbl_package_master p", // $join_table1
"p.id = u.package_id",
"tbl_user_master m", // $join_table2
"m.user_id = u.user_id",
"u.created_on", "ASC"
 );

at view/dashboard.php

foreach($form_data as $Res)
{
    echo $Res['activity_title'] . " :: ";
    echo $Res['created_on'];
}

It show empty result.

When I change the line return $result[$select]; to return $result; then it show 3 result but in array index no value...

How to show the result properly?


Solution

  • $query->row_array() returns only the first row of the result set, as an array with the fields you specified in the SELECT as its keys.

    I can't tell from your question whether you want to display only the first row or all of the rows in the result set, so: