我希望得到与所选图片相对应的所有相关图片

时间:2016-02-19 10:48:36

标签: php mysql codeigniter

我希望获得与所选照片相对应的所有相关照片.... 这是我的观点页面

<?php foreach($detail as $row){?>                                       
<img class="primary-image" ima="<?php echo base_url();?>images/<?php echo $row->image;?>" src="<?php echo base_url();?>images/<?php echo $row->image;?>" alt="" />                                          
<?php }?>

我的控制页面看起来像这样....

public function product_details($p_id)
{
    $data['active_mn']='product_details';
    $data['product']=$this->roxmodel->get_product_details($p_id);
    $data['productColor']=$this->roxmodel->get_product_color_details(null,$p_id)->result();

    $data['detail']=$this->roxmodel->get_related_image($p_id,4,0);
    var_dump($data['detail']);
    $this->load->view('product_details',$data);
}

我的模型页面看起来像这样......

public function get_related_image($p_id,$limit,$offset)
{
    $this->db->join('category','category.id=gallery.image');
    $this->db->where('category.id',$p_id);
    $this->db->order_by('gallery.id','desc');
    $query = $this->db->get('gallery',$limit,$offset)->result();
    return $query;
}

我的桌子包含衬衫,渴望,裤子图像和相应的category_ids是10,11,12当我选择category_id = 10 o衬衫图像我想得到所有category_id = 10衬衫图像和那样

这是我的表

id     image                category_id         
93   img1455604030.jpg       10              
94   img1455605183.jpg       11               
95   img1455616291.jpg       11                
96   img1455617201.jpg       10                
97   img1455617299.jpg       10                
98   img1455681918.jpg       13              
99   img1455681957.jpg       12               

这是我点击

查看图片的代码
<a href="<?php echo base_url();?>roxcontrol/product_details/<?php echo $row->id; ?>/<?php echo $row->category_id; ?>">

我的类别表就是这个

id  category_name   parent_id
8   men             0
9   kids            0
10  T-shirts        8
11  Shirts          8
12  Jeans           8
13  Pants           8
14  Shorts          8
15  Tees            9
16  Shirts          9
17  Jeans           9
18  Pants           9
19  Shorts & Ber    9
20  Romper          9

我的画廊表就是这个

id     image                category_id         
93   img1455604030.jpg       10              
94   img1455605183.jpg       11               
95   img1455616291.jpg       11                
96   img1455617201.jpg       10                
97   img1455617299.jpg       10                
98   img1455681918.jpg       13              
99   img1455681957.jpg       12  

1 个答案:

答案 0 :(得分:0)

加入查询中的模型文件存在错误。

category.id = gallery.image

之间没有任何关系

它应该是 category.id = gallery.category_id 作为您的表格结构。

尝试此查询。它可能对你有帮助。

public function get_related_image($id,$limit,$offset)
{
    $this->db->select('*');
    $this->db->from('gallery');
    $this->db->join('category','category.id=gallery.category_id');
    $this->db->where('category_id',$id);
    $this->db->limit($limit,$offset);
    $query = $this->db->get();
    return $query->result();

}