php – How to Filter Data in CodeIgniter with 2 tables (the Category Table and Category Activity table)-ThrowExceptions

Exception or error:

I have a problem in my code , actually i have 2 tables the category table and category_activity. then the id of category is connected to the category ID in the category_activity table. now when i want to select any category then I want to show only category activity connected to this category. is it possible? This is my code

 class Category extends MY_Controller {

        protected $data;

        public function __construct()

            if (!isset($this->session->userdata['users'])){


        public function index()
            $this->data['category_activity'] = $this->Category_model->getcategory_activity();
            $this->data['category'] = $this->Category_model->getcategory();
            $this->load->view('templates/master', $this->data);

This is my Category model

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Category_model extends CI_Model {

                 function getcategory_activity()
                       return $this->db->select('*')
                  function getcategory()
                           return $this->db->select('*')


This is my view code

<script type="text/javascript">
    //on each click, refresh visible / hidden for each product
    $('li.result').each(function(i, item){
      var category = $(this).data('category');
      var visible = $('input.filter[data-category="' + category + '"]:checked').length > 0;
      visible ? $(this).show() : $(this).hide();
    //if no checkboxes are checked, show all products
    if($('input.filter:checked').length === 0) $('li.result').show();

<div class="container">    
    <div class="row">
        <div class="col-xs-12 col-md-12 col-sm-12 text-center">
            <h3 class="text-center"> Category Filter in codeigniter</h3>
        <div class="col-md-12 col-sm-6 col-xs-12">
         <div class="col-md-3">
         <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
         <!-- Categories Panel -->
          <div class="panel panel-default">
          <!-- Heading -->
           <div class="panel-heading" role="tab" id="headingOne">
             <!-- Title -->
              <h4 class="panel-title">
                <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                <span> Categories</span>
            <!-- Title End -->
           <!-- Content -->
        <div id="collapseOne" class="panel-collapse" role="tabpanel" aria-labelledby="headingOne">
           <div class="panel-body categories">
                <?php $cnt=0; foreach ($category as $row):$cnt+=1;?>
                       <input type="checkbox" class="filter" data-category="<?php echo $row->id; ?>"  > <?php echo $row->category; ?>
                   <?php endforeach; ?>
        <!-- Categories Panel End -->
        <!-- Brands Panel -->
<table class="table">
 <?php foreach($category_activity as $data) {?>
          <td><?php echo $data->category_id; ?></td>
          <td><?php echo $data->activity; ?></td>
          <td><?php echo $data->qty; ?></td>
          <td><?php echo $data->eu_qty; ?></td>
          <td><?php echo $data->unit; ?></td>
          <td><?php echo $data->description; ?></td><br>
        <?php   }   ?>

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *