Welcome Guest, Not a member yet? Register   Sign In
Newbie: how to acces array values?
#1

[eluser]victor76[/eluser]
Hi,

I've got this Model function:
Code:
function get_last_ten_entries()
    {
        $query = $this->db->get('entries', 10);
        return $query->result();
                
    }

...and this Controller function:
Code:
<?php
class Blog_controller extends Controller {

    function blog()
    {
        $this->load->model('Blogmodel','',TRUE);

        $data['query'] = $this->Blogmodel->get_last_ten_entries();

        $this->load->view('blogview', $data);
    }
}
?>

In my View, I've used a simple print_r($data) to see if I would get anything from my DB.
This is wat it spits out:

Code:
Array
(
    [view] => blogview
    [vars] => Array
        (
            [query] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 1
                            [title] => 1st entry
                            [content] => blabla
                            [date] => 2007-10-18
                        )

                    [1] => stdClass Object
                        (
                            [id] => 2
                            [title] => 2nd entry
                            [content] => blabla
                            [date] => 2007-10-26
                        )

                )

        )

    [return] =>
)

...and now for my newbie question Smile
How can I acces these array values in my View?

I would like to display a simple <li>&lt;?php echo $data[0]['content']; ?&gt;</li>

But somehow this is not working...
Can anyone point me in some direction? Thnx!


Messages In This Thread
Newbie: how to acces array values? - by El Forum - 10-17-2007, 06:20 PM
Newbie: how to acces array values? - by El Forum - 10-17-2007, 07:05 PM
Newbie: how to acces array values? - by El Forum - 10-18-2007, 07:10 AM
Newbie: how to acces array values? - by El Forum - 10-18-2007, 07:35 AM
Newbie: how to acces array values? - by El Forum - 10-18-2007, 07:47 AM
Newbie: how to acces array values? - by El Forum - 10-18-2007, 08:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB