Click here to Skip to main content
14,875,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
PHP
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:
PHP
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.
PHP
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?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900