hi...iam stuck with this code pls help me

here is my controller

public function men_clothing() 
    {
        $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);
        $data['galllery']=$this->roxmodel->get_galleryImages($p_id);

    }

my model looks like this

public function get_galleryImages($p_id)
  {
    $this->db->where('category_id',$p_id);

    $query = $this->db->get('gallery')->result();
    return $query;
   /* $this->db->where('gallery.category_id',$p_id);
    $this->db->select('gallery.*,category.id');
    $this->db->join('category','category.parent_id=gallery.category_id');
    return $this->db->get('gallery')->result();
    */
  } 

my view page look like this

<?php foreach($galllery 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="" />
<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="" />

<?php }?>

here in the view page i need to display all images comes under men(value name) category..but its not displaying so plaese help me

Dani AI

Generated

asked for what the browser shows and reported var_dump => array size = 0. That narrows this to a data/parameter problem (the view loop is fine but the query returns no rows) or the controller never actually renders the view. Two quick, non-invasive checks to run first: var_dump the category id passed into the gallery method right before the call, and log the SQL the model builds with $this->db->last_query().

Most likely causes and fixes

  • Avoid assigning inside function calls. Expressions like get_category_by_parent($p_id = 8) set $p_id and can leave it with an unexpected value when used later. Use explicit variables instead so the gallery gets the intended id.
  • Make sure the controller actually loads the view and passes the data array.
  • Verify the gallery table column name matches what the model uses (category_id) and that there are rows for the chosen category id.

Example controller pattern to follow (use explicit ids and load the view)

public function men_clothing()
{
    $data['active_mn'] = 'men_clothing';
    $men_id  = 8;
    $kids_id = 9;

    $data['men']     = $this->roxmodel->get_category_by_parent($men_id);
    $data['kids']    = $this->roxmodel->get_category_by_parent($kids_id);
    $data['gallery'] = $this->roxmodel->get_galleryImages($men_id);

    $this->load->view('men_clothing', $data);
}

Other useful debug steps

  • In the model, after the query run log_message('debug', $this->db->last_query()); and var_dump($query) to see the actual SQL and result.
  • Run the same WHERE query directly in MySQL (e.g., SELECT COUNT(*) FROM gallery WHERE category_id = 8) to confirm data exists.
  • Confirm image files actually exist at the path used by base_url() (or check with file_exists(FCPATH . 'images/' . $row->image) in the view).
  • Standardize variable names (avoid typos like multiple Ls in galllery) so view keys match controller keys.

Following those checks will show whether the problem is the passed id, the DB data/schema, or a missing view/load step.

Recommended Answers

All 3 Replies

Show what your web page in the browser does show.

its not shwing any thing on the page then i had used var dumb then it shows array size=0

its not shwing any thing on the page then i had used var dumb then it shows array size=0

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.