The idea is to get every image with the specified tag. The image's details are in table Gallery, the relation between the image and the tag is in table Gallery_Rtags. I'm using this code successfully in another controller/view, but not with the relation between 2 tables here, so it's overwriting the image it gets in $data.
controller:
function id(){
$this->load->library('pagination');
$tag=str_replace("%20"," ",$this->uri->segment(3));
$query = $this->db->get_where('Gallery_Rtags',array('Rtag' => $tag));
$rows=$query->num_rows();
$config['base_url'] = 'http://example.com/gallery/index';
$config['total_rows'] = $rows;
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
foreach ($query->result() as $row)
{
$filename = $row->IDImg;
$data['query'] = $this->db->get_where('Gallery',array('Filename' => $filename),$config['per_page'],$this->uri->segment(4));
}
$data['rows']=$rows;
$data['main_content']='tag';
$this->load->view('template',$data);
}
view:
if ($rows > 0){
foreach ($query->result() as $row)
{
echo ('<div class="img_sq_g"><a href="http://example.com/image/id/'.$row->Filename.'"><img src="http://example.com/images/thumbs/'.$row->Filename.'_thumb'.$row->Extension.'"></a></div>');
}
echo $this->pagination->create_links();
}
I tried to add a counter that adds the query to an array but it didn't work.
foreach ($query->result() as $row)
{
$br = 0;
$filename = $row->IDImg;
$br2['br'] = $this->db->get_where('Gallery',array('Filename' => $filename),$config['per_page'],$this->uri->segment(4));
$br = $br + 1;
}
$data['query'] = $br2;
How do I modify it to get every image?