Example #1
0
?>
">
                <?php 
echo form_error('name');
?>
              </div>

              <?php 
if ($is_childable && $info['parent_id'] != 0) {
    ?>
              <div class="form-group">
                <label>Parent Category</label><p style="color:blue">Select only if you want to create a subcategory</p>
                <select name = "parent_id" class="form-control">
                  <option>Select Parent Category</option>
                  <?php 
    echo multilevel_select_category($parentable_categories, 0, array(), 0, set_value('parent_id', $info['parent_id']));
    ?>
                </select>
                <?php 
    echo form_error('parent_id');
    ?>
              </div>
              <?php 
}
?>
              <button class="btn btn-success" type="submit">Update</button>
              <button class="btn btn-warning" type="reset">Reset</button>

            </form>
          </div>
          <!-- col-lg-6 -->
Example #2
0
 function multilevel_select_category($categories, $parent_id = 0, $parents = array(), $level = 0, $parent = '')
 {
     /*static $i=0;
       static $k=0;
       if($k==0){
           $parent_cat = $parent;
           $k++;
       }*/
     if ($parent_id == 0) {
         foreach ($categories as $element) {
             if ($element['parent_id'] != 0 && !in_array($element['parent_id'], $parents)) {
                 $parents[] = $element['parent_id'];
             }
         }
     }
     $menu_html = '';
     foreach ($categories as $element) {
         if ($element['parent_id'] == $parent_id && $level < 1) {
             $menu_html .= '<option';
             if ($level == 0) {
                 $menu_html .= ' style="font-weight:bold;"';
             } else {
                 $menu_html .= ' style="font-style:italic;"';
             }
             $menu_html .= ' value="' . $element['id'] . '"';
             if ($element['id'] == $parent) {
                 $menu_html .= " selected";
             }
             $menu_html .= '>';
             $menu_html .= $element['name'] . '</option>';
             if (in_array($element['id'], $parents)) {
                 $i++;
                 $menu_html .= multilevel_select_category($categories, $element['id'], $parents, $level + 1, $parent);
             }
         }
     }
     $i--;
     return $menu_html;
 }