CodeIgniter Forums
Parsing Database Results - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Parsing Database Results (/thread-40831.html)



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

[eluser]ShoeLace1291[/eluser]
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:
Code:
$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

[eluser]danmontgomery[/eluser]
You're just merging an array with an empty array, what are you expecting to happen?


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

[eluser]ShoeLace1291[/eluser]
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.