我想根据所选的category_id仅显示那些图像但是我没有在这里获得图像,并且对于所有category_id,显示的值是category_id = 9
这是我的控制器
public function men_clothing($p_id=null)
{
$data['active_mn']='men_clothing';
$data['men']=$this->roxmodel->get_category_by_parent($p_id=8);
$data['kids']=$this->roxmodel->get_category_by_parent($p_id=9);
$config['base_url'] = base_url().'roxcontrol/men_clothing';
$config['per_page'] = 9;
$config['uri_segment'] = 3;
$config['total_rows'] = $this->roxmodel->count_gallery();
$data['galllery']=$this->roxmodel->get_gallery_men_images($p_id,$config['per_page'],$this->uri->segment(3));
var_dump($data['galllery']);
$this->load->library('pagination',$config);
$data['page_links'] = $this->pagination->create_links();
$this->load->view('men_clothing',$data);
}
这是我的模特
public function get_gallery_men_images($p_id=null)
{
$this->db->where('gallery.category_id',$p_id);
$this->db->select('gallery.*,category.category_name');
$this->db->join('category','category.id=gallery.category_id');
return $this->db->get('gallery')->result();
}
这是我的观看页面
<ul class="sidebar-tags">
<li><a href="<?php echo base_url();?>roxcontrol/men_clothing">View All </a></li>
<?php foreach($men as $row) {?>
<li><a href="<?php echo base_url();?>roxcontrol/men_clothing/<?php echo $row->id; ?>"><?php echo $row->category_name; ?> <span> </span></a></li>
<?php } ?>
</ul>
<?php if( !empty($galllery) ) {
foreach($galllery as $row){?>
<div class="col-lg-4 col-md-4 col-sm-4">
<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="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->category_id;?>"><?php echo $row->title;?></a></h2>
<p><?php echo $row->description;?></p>
</div>
</div>
<!-- single-product end -->
</div>
</div>
<?php }}?>
这里图像没有显示并且像这样
SELECT `gallery`.*, `category`.`category_name` FROM `gallery` JOIN `category` ON `category`.`id`=`gallery`.`category_id` WHERE `gallery`.`category_id` = 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
答案 0 :(得分:0)
您的加入查询
存在问题$this->db->select('*');
$this->db->from('gallery');
$this->db->where('category.id',$p_id);
$this->db->join('category', 'category.id = gallery.category_id');
$query = $this->db->get()->result();
return $query;
答案 1 :(得分:0)
如果你想要的是获取或过滤具有相同category_id的结果:查询应该是这样的
public function get_gallery_men_images($p_id=null)
{
$img = $this->db->select('gallery.*')
// why not add condition IF p_id = null
// execute only if p_id not null otherwise it return error
if($p_id != null):
->where('gallery.category_id',$p_id)
endif;
// we are using LEFT JOIN to fetch the category data's
->join('category','category.id=gallery.category_id', 'left')
->get('gallery');
return $img->result();
}