CodeIgniter Forums
How to select posts followers in a blog application - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to select posts followers in a blog application (/showthread.php?tid=55574)



How to select posts followers in a blog application - El Forum - 11-01-2012

[eluser]hkboateng[/eluser]
I am doing a blog application and having problems generating the sql query to pull both the current users posts and followers posts.

Database:
Table Friends->f_username, user_friend, friendsid
Post->postid, posts, posts_username
Code from Model
Code:
public function get_posts()
     {
        $fog = array(
            'username'=>$this->session->userdata('username')//User who is currently signedin
                );
        $fogs = array(
            'posts.username'=> 'friends.f_username'
        );
                            $this->db->select();
                            $this->db->where('posts', $fog);
                            $this->db->or_where('post, friends',$fogs);
                $records = $this->db->get();
            return $records->result();  
        if($records->num_rows() > 0)
        {
            $row = $records->row();
                 echo $row->username;
                 echo $row->post;
                 echo $row->created;
                 echo $row->postid;
        } else {
             return false;
            }
        }

Code from Controller
Code:
$data['posts'] = $this->blog_model->users_post();
            $data['friend'] = $this->blog_model->list_friends();
           $this->load->view('users_post',$data);

Code from View
Code:
<div id="user-posts">
                   <hr id="hr">
                   &lt;?php foreach($records as $row) {?&gt;
                       <span id="pts_user">
                    <b>&lt;?php echo $row->username;?&gt;</b>
                </span>
                      &lt;?php echo $row->postid;?&gt;
                        <span id="pts_created">
                            <b>&lt;?php echo $row->created; ?&gt;</b>
                        </span>
                   <p>&lt;?php echo $row->post;?&gt;</p>
                   <hr id="hr">
                    
                   &lt;?php }?&gt;
                  
                  
            <div>

Need help whether the fault is from the SQL query.