Guest User

Untitled

a guest
Jul 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. ----------------------------------------------------------------------------------------
  2. view
  3. ----------------------------------------------------------------------------------------
  4.  
  5.  
  6. <div class="columnFull last">
  7.    
  8.     <?php $categories = $this->categoryModel->getCategories(); ?>
  9.     <?php foreach ($categories as $category):?>
  10.     <!-- get all categories with no parent category from the database and loop through them -->
  11.     <div class="blockHead">
  12.         <?php echo $category->cat_name ?>
  13.         <!-- echo the categorys name -->
  14.     </div>
  15.     <div class="blockBody">
  16.         <?php $sub_categories = $this->categoryModel->getCategories($category->cat_id); ?>
  17.         <?php foreach ($sub_categories as $sub_categories):?>
  18.         <!-- get all categories with the currently looping category as their parent category from the database -->
  19.             <div class="blockHead top20">
  20.                 <?php echo $sub_categories->cat_name ?>
  21.                 <!-- echo the sub-categorys name -->
  22.             </div>
  23.         <?php endforeach;?>
  24.     </div>
  25.     <?php endforeach;?>
  26.  
  27. </div>
  28.  
  29.  
  30. ------------------------------------------------------------------------------------------------------
  31. categoryModel
  32. ------------------------------------------------------------------------------------------------------
  33.  
  34. <?php
  35. function getCategories($category = 0)
  36.     {
  37.     $query = $this->db->get_where('categories', array('cat_parent' => $category));
  38.         return $query->result();
  39.     }
  40. ?>
Add Comment
Please, Sign In to add comment