Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:02:05+00:00 2026-06-08T18:02:05+00:00

My table [cat_id,title,pid] . I need to get all the child sub-categories ID`s in

  • 0

My table [cat_id,title,pid]. I need to get all the child sub-categories ID`s in the following format:

[1] =>Array ( [cat_id] => 2 [title] => TEST [pid] => 1 ),

[2] =>Array ( [cat_id] => 3 [title] => TEST [pid] => 1 ),

[3] =>Array ( [cat_id] => 4 [title] => TEST [pid] => 2 ), 

[4] =>Array ( [cat_id] => 5 [title] => TEST [pid] => 3 ) 

Purpose – using ID`s of the childs, to get all of these items.

I tried to do something as the following code, but it does not work:

public function get_ids($tree,$cid = 0)
{

    $data = $this->db->select('cat_id, title, pid')
                     ->where('pid',$cid)
                     ->get('catalog');

    $result = array_push($tree,$data->result_array());

    if($data->num_rows() > 0){

        foreach ($data->result_array() as $r) {

            return $this->get_ids($result,$r['cat_id']);

        }   
    }
    else{
        return $result;
    }
}

Maybe there is better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:02:08+00:00Added an answer on June 8, 2026 at 6:02 pm

    Try the below code to get all child ids by given parent id.

    function fnGetChildCatelogs($id) {
    
        $qry = "SELECT cat_id FROM catalog WHERE pid = $id";
    
        $rs = mysql_query($qry);    
    
        $arrResult = array();    
    
        if(mysql_num_rows($rs) > 0) {
    
            # It has children, let's get them.
    
            while($row = mysql_fetch_array($rs)) {
    
                # Add the child to the list of children, and get its subchildren
    
                $arrResult[$row['cat_id']] = fnGetChildCatelogs($row['cat_id']);
    
            }
    
        }
    
        return $arrResult;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following tables: CATEGORIES -- entry_id, cat_id TITLES -- entry_id, title DATA
Ok now i have two table categories and subcategories like this Categories: id title
I have following tables articles_category id title sef_title articles_data id cat_id title sef_title details
I have categories table: cat_id cat_name Than categories - posts relationship table cat_rel :
I have a simple cakephp app with table articles that has a cat_id column
Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get
I use the following code which works perfectly in all browsers except Chrome and
I have a mysql table containing news data and categories and i'm trying to
I am using the following query to get the count from multiple tables:- SELECT
I have two table posts & categories post_id | post_title | post_content | post_cat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.