[英]mysql. I want to get the max value of all rows with a specific date and use the corresponding fields
[英]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.