我希望获得与所选照片相对应的所有相关照片.... 这是我的观点页面
<?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 }?>
我的观看页面是这个
<?php foreach($detail as $row){?>
<!-- product start -->
<div class="col-lg-3 col-md-3 col-sm-3">
<div class="two-product">
<!-- single-product start -->
<div class="single-product">
<!-- <span class="sale-text">Sale</span>-->
<div class="product-img">
<a href="#">
<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="" />
<img class="secondary-image" ima="<?php echo base_url();?>images/<?php echo $row->image;?>" src="<?php echo base_url();?>images/<?php echo $row->image;?>" alt="" />
</a>
<div class="action-zoom">
<div class="add-to-cart">
<a href="<?php echo base_url()?>images/<?php echo $row->image ?>" data-toggle="modal-image" title="Quick View"><i class="fa fa-search-plus"></i></a>
</div>
</div>
<div class="actions">
<div class="action-buttons">
</div>
</div>
<!-- <div class="price-box">
<span class="new-price">$110.00</span>
</div>-->
</div>
<div class="product-content">
<h2 class="product-name"><a href="<?php echo base_url();?>roxcontrol/product_details/<?php echo $row->id;?>"><?php echo $row->title;?></a></h2>
<p><?php echo $row->description;?></p>
</div>
</div>
<!-- single-product end -->
</div>
</div>
<?php }?>
我的控制页面看起来像这样......
public function product_details($p_id)
{
$data['active_mn']='product_details';
$data['product']=$this->roxmodel->get_product_details($p_id);
$id = $this->input->post['category_id'];
$data['detail']=$this->roxmodel->get_related_image($id,4,0);
var_dump($data['detail']);
$this->load->view('product_details',$data);
}
我的模型页面看起来像这样
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();
}
这是我的表库(表名)
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; ?>">
my category table is this..
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
我的桌子包含衬衫,T恤,裤子图片及其对应的category_ids是10,11,12当我选择category_id = 10衬衫图片时我想得到所有category_id = 10件衬衫图片下的相关产品和那样
问题是category_id值为null我没有得到category_id值
答案 0 :(得分:0)
我想你想在类别table.right中获取特定类别id的所有图像。如果是这样改变你的模型 模型
public function get_related_image($id)
{
$this->db->select('*');
$this->db->from('gallery');
$this->db->join('category','category.id=gallery.category_id');
$this->db->where('category.id',$id);
$query = $this->db->get();
return $query->result();
}
控制器
public function product_details($p_id)
{
$data['active_mn']='product_details';
$data['product']=$this->roxmodel->get_product_details($p_id);
$data['detail']=$this->roxmodel->get_related_image($p_id);
var_dump($data['detail']);
$this->load->view('product_details',$data);
}
查看
<input type="text" name="categoryid">
我们加入了两个table.so类别名称也得到了这个结果
echo $row->category_name;
答案 1 :(得分:0)
这是问题...... 改变模型中的条件
From: $this->db->where('category_id',$id);
To(Change) : $this->db->where('category.id',$id);
立即检查......
答案 2 :(得分:0)
你正在限制
$this->db->limit($limit,$offset);
尝试
$this->db->limit($limit);
答案 3 :(得分:0)
<a href="<?php echo base_url();?>roxcontrol/product_details/<?php echo $row->id; ?>/<?php echo $row->category_id; ?>">abc</a>
COntroller代码应为此
public function product_details($p_id, $category_id)
{
$data['active_mn']='product_details';
$data['product']=$this->roxmodel->get_product_details($p_id);
$data['detail']=$this->roxmodel->get_related_image($category_id,4,0);
var_dump($data['detail']);
$this->load->view('product_details',$data);
}