neohacksus
neohacksus

Reputation: 39

JOIN TABLES in CODEIGNITER ISSUE

I have Fours tables tto join.

Tables in DB

My model code:

public function get_all_customers()
{

    $this->db->select('*, customerID, custstr, CONCAT(custstr, '.', customerID) AS custcode')->from('customers');

$this->db->join('deliverydays', 'customers.DeliveryDaysID = deliverydays.DeliveryDaysID', 'left');
$this->db->join('deliveryman', 'customers.DeliveryPersonID=deliveryman.DeliveryManID');
$this->db->join('reference', 'reference.referenceID=customers.referenceID');
$this->db->order_by('customerID','asc');         
$query = $this->db->get(); 

   return $query->result_array();
}

My Controller Code:

$customers=$this->customer_model->get_all_customers(); 
$data ['customers'] = $customers;
$this->loadViews("customer_view", $this->global,  $data);

View code is:

<?php foreach($customers as $customer){?>
             <tr role="row" class="" >
                 <td class="sorting_1"><?php echo $customer->custcode;?></td>
                 <td><?php echo $customer->Name;?></td>
                <<td><?php echo $customer->dmName;?></td>
                 <td><?php echo $customer->referenceName;?></td>
    </tr><?php }?>

PROBLEM

Problem is that it is giving errors

Message: Trying to get property of non-object

Where is issue? I an not figure it out.

Upvotes: 0

Views: 22

Answers (1)

user5139148
user5139148

Reputation:

This issue is cause because you returning data from your model as array format result_array() and you retrieving as object in view page.

So Change your model return as following code

return $query->result();

Hope it will solve...

Upvotes: 1

Related Questions