title: Codeigniter add multiple category to a course (Academy-LMS)
body: <p>I am using <a href="http://codecanyon.net/item/academy-course-based-learning-management-system/22703468" rel="noreferrer">Academy LMS</a> Source code is in <a href="https://github.com/getdinerotoday/academyLMS" rel="noreferrer">Github</a>
  it's a Learning Management system and it is designed to have one category per course</p>
  <p>I want to add multiple categories to one course</p>
  <p>In <a href="https://github.com/fopp-dev/Academy-LMS-customize/blob/master/application/controllers/Api.php" rel="noreferrer">/controllers/API.php</a> I have</p>
  <pre><code>  // Fetch all the categories
    public function categories_get($category_id = &quot;&quot;) {
      $categories = array();
      $categories = $this-&gt;api_model-&gt;categories_get($category_id);
      $this-&gt;set_response($categories, REST_Controller::HTTP_OK);
    }
  
    // Fetch all the courses belong to a certain category
    public function category_wise_course_get() {
      $category_id = $_GET['category_id'];
      $courses = $this-&gt;api_model-&gt;category_wise_course_get($category_id);
      $this-&gt;set_response($courses, REST_Controller::HTTP_OK);
    }
  </code></pre>
  <p>then in <a href="https://github.com/fopp-dev/Academy-LMS-customize/blob/master/application/models/Api_model.php" rel="noreferrer">/models/Api_model.php</a>, I have</p>
  <pre><code>// Get categories
  public function categories_get($category_id)
  {
      if ($category_id != &quot;&quot;) {
          $this-&gt;db-&gt;where('id', $category_id);
      }
      $this-&gt;db-&gt;where('parent', 0);
      $categories = $this-&gt;db-&gt;get('category')-&gt;result_array();
      foreach ($categories as $key =&gt; $category) {
          $categories[$key]['thumbnail'] = $this-&gt;get_image('category_thumbnail', $category['thumbnail']);
          $categories[$key]['number_of_courses'] = $this-&gt;crud_model-&gt;get_category_wise_courses($category['id'])-&gt;num_rows();
      }
      return $categories;
  }
  
  // Get category wise courses
  public function category_wise_course_get($category_id)
  {
      $category_details = $this-&gt;crud_model-&gt;get_category_details_by_id($category_id)-&gt;row_array();
  
      if ($category_details['parent'] &gt; 0) {
          $this-&gt;db-&gt;where('sub_category_id', $category_id);
      } else {
          $this-&gt;db-&gt;where('category_id', $category_id);
      }
      $this-&gt;db-&gt;where('status', 'active');
      $courses = $this-&gt;db-&gt;get('course')-&gt;result_array();
  
      // This block of codes return the required data of courses
      $result = array();
      $result = $this-&gt;course_data($courses);
      return $result;
  }
  </code></pre>
  <p>then in <a href="https://github.com/fopp-dev/Academy-LMS-customize/blob/master/application/models/Crud_model.php" rel="noreferrer">/model/Crud_model.php</a>, I got</p>
  <pre><code>    public function get_category_details_by_id($id)
      {
          return $this-&gt;db-&gt;get_where('category', array('id' =&gt; $id));
      }
  
   function get_category_wise_courses($category_id = &quot;&quot;)
      {
          $category_details = $this-&gt;get_category_details_by_id($category_id)-&gt;row_array();
  
          if ($category_details['parent'] &gt; 0) {
              $this-&gt;db-&gt;where('sub_category_id', $category_id);
          } else {
              $this-&gt;db-&gt;where('category_id', $category_id);
          }
          $this-&gt;db-&gt;where('status', 'active');
          return $this-&gt;db-&gt;get('course');
      }
  </code></pre>
  <p>in SQL course table has a column named category_id int(11) which stores one category per course I've changed it to TEXT format and put comma-separated values like 1,2,3 and used the ways like</p>
  <pre><code>$this-&gt;db-&gt;where_in('category_id',$category_id)
  </code></pre>
  <p>and</p>
  <pre><code>$this-&gt;db-&gt;like('category_id',$category_id)
  </code></pre>
  <p>and</p>
  <pre><code>$this-&gt;db-&gt;where(&quot;FIND_IN_SET(&quot;.$category_id.&quot;,category_id) &gt;&quot;, 0);
  </code></pre>
  <p>and got no result I just need courses to have comma-separated values in the category_id column</p>
  <p>Simply, I want courses to have multiple categories</p>
  <p>DB tables
  <a href="https://pasteboard.co/JNSxO2kz.png" rel="noreferrer">https://pasteboard.co/JNSxO2kz.png</a></p>
  <p>course table
  <a href="https://pasteboard.co/JNSy7g0.png" rel="noreferrer">https://pasteboard.co/JNSy7g0.png</a></p>
  <p>category table
  <a href="https://pasteboard.co/JNSyhlk.png" rel="noreferrer">https://pasteboard.co/JNSyhlk.png</a></p>
  <p>category_id table (Mapping Table suggested by @micheal-la-ferla )
  <a href="https://pasteboard.co/JNSyGGn.png" rel="noreferrer">https://pasteboard.co/JNSyGGn.png</a></p>
  <p>anybody could help?</p>