$errors[] = "the category is already exist"; $_SESSION['errors'] = $errors; } if (empty(trim($_GET['desc']))) { $errors[] = "the desc is empty"; $_SESSION['errors'] = $errors; } if (empty($errors)) { $category->category_name = $_GET['name']; $category->category_desc = $_GET['desc']; $category->insert(); } $data = $category->getallcategory(); $response1 = []; $response1[] = $data; $response1[] = $errors; $jsondata = json_encode($response1); echo $jsondata; // $category = new category(); // $category->category_name = $_GET['name']; // $category->category_desc = $_GET['desc']; // $category->insert(); // $data = $category->getallcategory(); // $jsondata = json_encode($data); // echo $jsondata; } else { $cat = new category(); $jsondata = json_encode($cat->getallcategory()); echo $jsondata; } }
<div class="panel panel-default sidebar-menu"> <div class="panel-heading"> <h3 class="panel-title">Categories</h3> </div> <div class="panel-body"> <ul class="nav nav-pills nav-stacked category-menu"> <?php include "../category.php"; include "../sub-category.php"; ?> <?php $cat = new category(); $data = $cat->getallcategory(); $sub = new subcategory(); for ($i = 0; $i < count($data); $i++) { ?> <li> <a href="category.php?cat_id=<?php echo $data[$i]['category_id']; ?> "><?php echo $data[$i]['category_name']; ?> <span class="badge pull-right">42</span></a> <ul> <?php $subdata = $sub->getsubbycat($data[$i]['category_id']); for ($j = 0; $j < count($subdata); $j++) {