繁体   English   中英

我想获取与所选图片相对应的所有相关图片

[英]i want to get all related pics corresponding to the pic selected

我想获取与所选图片相对应的所有相关图片。...这是我的查看页面`

<?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_id = 10 o衬衫图像时,它们对应的category_ids为10、11、12,我想获取所有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  

联接查询中您的模型文件存在错误。

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();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM