So basically I have a helper –
function records()
{
$ci = get_instance();
$ci->db->order_by("date", "desc");
$ci->db->limit(20);
$query = $ci->db->get('records');
$data =array();
foreach($query->result_array() as $orders)
{
$data[] = $orders;
}
return $data;
}
I need to pass data from it to view, but currently I’m only passing data from table records. In additional, after I get $data[] from records, I need to check the current record id, and then pass in the same $data[] all user details from another table which is users instead. How can I do it? So basically I muts first get all data from records, check from what user the record is, and then search that user with get_where(‘users’, array(‘id’ => $data[‘user_id’])); and add user data to either new array or the same $data[] array. Is this something doable? If yes, please show me example of it.
I think you want to do a join?
http://codeigniter.com/user_guide/database/active_record.html
Make sure you modify the query to use the correct field name in the records table that references the user’s id. The above comments are right though – helpers are absolutely not the place for queries. Really, I can’t think of any good example of using get_instance to grab the CI object in a helper, they should probably be CI independent functions.