This is my join table:
Model
public function blog_list()
{
$this->db->select('b.id, bl.id_p, u.name, bl.cat2, b.vote');
$this->db->join('blog b', 'bl.id_p = b.id_p');
$this->db->join('users u', 'u.id = bl.id_p');
$this->db->from('blog_list bl');
$this->db->get();
}
And my problem is that when I try echo all records from column for example id_p I get this records from blog table instead from blog_list. I try reverse blog with blog_lists and try different types of joining table, without expecting result.
controller:
public function index()
{
$data['blog_list'] = $this->users_m->blog_list();
$where = "id_p = " . $this->session->userdata('id');
$data['user'] = $this->users_m->get('blog_list',$where,TRUE);
$this->load->view('blog/blog_list', $data);
}
view:
<?php foreach($blog_list as $row): ?>
<?php echo ($row->name); ?>
<?php echo ($row->id); ?>
<?php echo ($row->id_p); ?>
<?php echo ($row->vote); ?>
<?php echo ($row->cat2); ?>
<?php echo anchor('blogs/blog/' . $row->id_p , 'Odwiedź >>'); ?>
<br><br>
<?php endforeach; ?>
Please try this:
public function blog_list()
{
$this->db->select('b.id_p, bl.id_p, u.name, bl.cat2, b.vote');
$this->db->from('blog_list bl');
$this->db->join('blog b', 'b.id_p = bl.id_p');
$this->db->join('users u', 'u.id = bl.id_p');
$query = $this->db->get();
}
public function blog_list()
{
$this->db->select('b.id_p AS blog_id,
bl.id_p AS blog_list_id,
u.name AS user_name,
bl.cat2 AS blog_list_cat,
b.vote AS blog_vote');
$this->db->from('blog_list bl');
$this->db->join('blog b', 'b.id_p = bl.id_p');
$this->db->join('users u', 'u.id = bl.id_p');
$query = $this->db->get();
}
And in code :
<?php foreach($blog_list as $row): ?>
<?php echo ($row->user_name); ?>
<?php echo ($row->blog_id); ?>
<?php echo ($row->blog_list_id); ?>
<?php echo ($row->blog_vote); ?>
<?php echo ($row->blog_list_cat); ?>
<?php echo anchor('blogs/blog/' . $row->blog_list_id , 'Odwiedź >>'); ?>
<br><br>
<?php endforeach; ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.