Welcome Guest, Not a member yet? Register   Sign In
Trying to figure out how to get related portfolios
#1

Hi there,

I am trying to figure out how to get related portfolios depending on the category of the one they are looking at.  I have the following that works but it has the category hard coded and I cannot for the life of me see a way of doing it.

Code:
  public function get_relatedportfolios() {
      $this->db->select('*');
      $this->db->from('cms_portfolio');
      $this->db->where('category_id', 'Retail');
      $this->db->limit(5);
      $query = $this->db->get();
      return $query->result();
  }

As you can see in my where section has 'Retail' added, I am trying to figure out how I can get information from the page to get the category_id of which ever they are bringing up so I can get the others that are around.

Thanks
Reply
#2

If you're looking at a portfolio, you might have the portfolio ID in the URL. You would query the database for that portfolio's category, and then you would have it.

If you're looking at a portfolio category, you might have the portfolio category name or ID in the URL. You would use $this->uri->segement(x) to get it.

So, the data is always there, you just might require more queries or method calls to do what you want to do.

Does this help?
Reply
#3

Get the category ID of the portfolio they're looking at, and pass it to get_relatedportfolios().

In your controller:
PHP Code:
// assuming the current portfolio is in an array called $portfolio[] and assuming your model is called portfolio_model
$relatedportfolios $this->portfolio_model->get_relatedportfolios($portfolio['category_id']); 

In your model:
PHP Code:
public function get_relatedportfolios($category_id) {
    
$this->db->select('*');
    
$this->db->from('cms_portfolio');
    
$this->db->where('category_id'$category_id);
    
$this->db->limit(5);
    
$query $this->db->get();
    return 
$query->result();

Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB