Welcome Guest, Not a member yet? Register   Sign In
How to select posts followers in a blog application
#1

[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.




Theme © iAndrew 2016 - Forum software by © MyBB