Philip Kirkbride
Philip Kirkbride

Reputation: 22879

CodeIgniter going from passing a single row to multiple rows

I'm building a site using CodeIgniter. I have lots of experience using SQL with PHP but having some trouble working through CodeIgniter.

I'm using the following code to set userdata to hold a logo from my database.

Currently I only have 1 logo and it works fine but I need to edit it to handle multiple logos.

        $query3 = $this->db->query('SELECT file FROM ohes_flyer_logos');
        $row3 = $query3->row();

        $data = array( 'userlogo' => $row3->file );
        $this->session->set_userdata($data);

Where the Logos are listed...

echo $this->session->userdata('userlogo'); 

How can I edit this to pass through a full list of logos, and echo them all out?

Upvotes: 0

Views: 304

Answers (1)

Chris Schmitz
Chris Schmitz

Reputation: 8247

Calling row() grabs only a single record. You probably want to use result() or result_array() and pass that to the view where you can loop through them. For example:

$query3 = $this->db
    ->query('SELECT file FROM ohes_flyer_logos')
    ->result();

$data = array('userlogo' => $query3);
$this->session->set_userdata($data);

Then in your view, you can do this:

foreach ($userlogo as $logo)
{
    echo $logo->file; // do your processing here
}

Upvotes: 2

Related Questions