I want to get all the related pics corresponding to the pic selected....
here is my view page

<?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 }?>

my control page looks like this....

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

my model page looks like this

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

}

here is my table-gallery(table name)

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  

this is my code to view image by clicking

<a href="<?php echo base_url();?>roxcontrol/product_details/<?php echo $row->id; ?>/<?php echo $row->category_id; ?>">

my table contains shirts,tshirts,pants images and their corresponding category_ids are 10,11,12 when i choose the category_id=10 shirt image i want to get all category_id=10 shirt images under the related products and like that

the problem is category_id value is null iam not getting category_id value

Dani AI

Generated

Short diagnosis (from post + hint): the link is passing the category id in the URL segments, but the controller is trying to read it from POST. Also the current line uses array syntax on CodeIgniter input (which is incorrect). That combination makes category_id come back null.

A simple fix is to accept the category as a second method parameter (or read the correct URI segment) and use that value when calling the related-images model. Example controller pattern:

public function product_details($image_id, $category_id = NULL)
{
    $data['product'] = $this->roxmodel->get_product_details($image_id);
    $cat = $category_id ?: $this->uri->segment(4) ?: ($data['product']->category_id ?? NULL);
    $data['related'] = $this->roxmodel->get_related_image($cat, 4, 0, $image_id);
    $this->load->view('product_details', $data);
}

A small model tweak helps avoid showing the same image in related results (pass the current image id to exclude it):

public function get_related_image($category_id, $limit, $offset, $exclude_id = NULL)
{
    $this->db->where('gallery.category_id', $category_id);
    if ($exclude_id) $this->db->where('gallery.id !=', $exclude_id);
    $this->db->limit($limit, $offset);
    return $this->db->get('gallery')->result();
}

Quick checklist for troubleshooting:

  • Confirm the rendered anchor actually contains the category value (view page source).
  • Use var_dump($this->uri->segment_array()) or var_dump($this->input->post()) while debugging.
  • If relying on POST, the form must send category_id and use $this->input->post('category_id') (function-call syntax).
  • Remove debug var_dumps before deploying.

These changes align the data source (URI vs POST) with how the controller reads it and will stop category_id being null.

Member Avatar for Member #120589
$id = $this->input->post['category_id'];

Check what that line gives

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.