Skip to content

Instantly share code, notes, and snippets.

Verifying myself: My Bitcoin username is +jake. https://onename.io/jake
@Jakeii
Jakeii / controller.php
Last active April 27, 2018 10:08
Get categories and subcategories in one query, seen many solutions that get the categories and for each category check for subcategories. Uses codeigniter framework, fairly easy to convert to vanilla php if you need. Probably a better storage/display solution than the strange array that I used.
<?php
$cats_result = $this->model->get_categories($swapid);
if ($cats_result->num_rows() > 0) {
$cat_index = $sub_index = $row_index = 0;
do {
$cats[$cat_index]['cat'] = array(
'name' => $cats_result->row($row_index)->cat_name,
'title' => $cats_result->row($row_index)->cat_title
);