Welcome Guest, Not a member yet? Register   Sign In
Can echo out of controller but don't understand how pass to view?
#11

[eluser]Jackattack[/eluser]
My Controller

Code:
foreach ($query->result() as $row)
        {
            $view_data['total_results']=$query->result();
        }
        $this->output->enable_profiler(TRUE);
        $this->load->view('home_view', $view_data);

My View
Code:
<?php foreach($total_results as $row): ?>
    <tr>
        <td>&lt;?=$row['name']?&gt;</td>
        <td>&lt;?=$row['id']?&gt;</td>
    </tr>
    &lt;?php endforeach; ?&gt;

It is a little different from my previous post but hopefully we can solve this. Thanks so much!
#12

[eluser]Pascal Kriete[/eluser]
Yup, found the error. When using:
Code:
$query->result();
It returns an object, so you access your variables using
Code:
$row->name
$row->id

To get an associative array do:
Code:
$query->result_array();
#13

[eluser]Beren[/eluser]
Ah, the problem here is (I think) you are getting a result object and foreach is wanting an array, use instead
Code:
$my_results = $query->result_array();
That should do it
#14

[eluser]Jackattack[/eluser]
Thanks a million guys!




Theme © iAndrew 2016 - Forum software by © MyBB