Return more than one row from a specific table in database
You seem to be missing braces in your for loop:
foreach ($query->result_array() as $row) // give array variable the value row_array { // grab specific elements from row and assign to variables $row['id']; $row['to_id']; $row['to_user']; $row['from_id']; $row['from_user']; $row['time_sent']; $row['subject']; $row['message']; $row['opened']; $row['replied']; }
A for loop only applies to the first line unless you surround the body in braces.
First, bear in mind that I am not very familiar with CodeIgniter. Your problem, however, is fairly generic PHP:
foreach ($query->result_array() as $row) // give array variable the value row_array // grab specific elements from row and assign to variables $row['id']; $row['to_id']; $row['to_user']; $row['from_id']; $row['from_user']; $row['time_sent']; $row['subject']; $row['message']; $row['opened']; $row['replied']; $this->load->view('messages/inbox', $row);}
Every time you encounter a row, you're calling $this->load->view()
. I believe you should only be calling the view once, with all the data you want to pass. You probably want to do something like this:
$data = array();foreach ($query->result_array() as $row) { $data[] = array ( 'id' => $row['id'], 'to_id' => $row['to_id'], 'to_user' => $row['to_user'], 'from_id' => $row['from_id'], 'from_user' => $row['from_user'], 'time_sent' => $row['time_sent'], 'subject' => $row['subject'], 'message' => $row['message'], 'opened' => $row['opened'], 'replied' => $row['replied'] );}$this->load->view('messages/inbox', $data);
You would then need to process multiple messages in your view.