[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">
<?php foreach($records as $row) {?>
<span id="pts_user">
<b><?php echo $row->username;?></b>
</span>
<?php echo $row->postid;?>
<span id="pts_created">
<b><?php echo $row->created; ?></b>
</span>
<p><?php echo $row->post;?></p>
<hr id="hr">
<?php }?>
<div>
Need help whether the fault is from the SQL query.