分页查询与2个表之间的关系 [英] Pagination query with relation between 2 tables

查看:115
本文介绍了分页查询与2个表之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的想法是使用指定的标签获取每个图像。图像的详细信息在表格库中,图像和标记之间的关系在表格Gallery_Rtags中。我在另一个控制器/视图中成功使用此代码,但不是这里有两个表之间的关系,所以它覆盖了它在$ data中获得的图像。



controller:

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?

推荐答案

数据。



控制器:

data.

controller:
function id(){


this-> load-> library(' pagination');
this->load->library('pagination');


tag = str_replace( %20
tag=str_replace("%20"," ",


这篇关于分页查询与2个表之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆