CodeIgniter Forums
Parsing Database Results - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Parsing Database Results (/thread-40831.html)

Parsing Database Results - El Forum - 04-19-2011

I realize that there is a section in the user guide about this, but I'm trying to parse database results but with a little more to it.

This is my controller:
$query = $this->db->query("
            SELECT *
            FROM albums
            WHERE author_id = ".$member['id']."
            ORDER BY id DESC LIMIT 5");
        $albums = array();
        foreach($query->result_array() as $album){
            $author = $this->member->context($album['author_id']);
                $query2 = $this->db->query("
                    SELECT *
                    FROM photos
                    WHERE album_id = ".$album['id']."
                    ORDER BY RAND()
                    LIMIT 1");
                $cover = $query2->row_array();
            $member_album = array(
                        'ALBUM_ID' => $album['id'],
                        'ALBUM_TITLE' => $album['title'],
                        'ALBUM_DESCRIPTION' => nl2br(htmlspecialchars($album['description'])),
                        'ALBUM_LINK' => anchor('gallery/albums/'.url_title($album['title']).'/'.$album['id'], $album['title']),
                        'ALBUM_COVER' => anchor('gallery/photos/'.url_title($cover['title']).'/'.$cover['id'], "<img src='".base_url()."/attachments/".$cover[' width='295' height='150' title='".$album['>"),
                        'ALBUM_POST_DATE' => date('M jS, Y', $album['date_posted'])
            $albums = array_merge($albums, $member_album);
        $data = array(
                'MEMBER_ALBUMS' => $albums
        $this->parser->parse('gallery/gallery_index.tpl', $data);

All the code does is display the variables as is. When I print the array, it displays just like the user guide example arrays do.

Parsing Database Results - El Forum - 04-20-2011

You're just merging an array with an empty array, what are you expecting to happen?

Parsing Database Results - El Forum - 04-20-2011

I'm trying to create an array that looks like the one in the user guide. But if I use $member_album[] that will mess it up.