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 8204903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:02:35+00:00 2026-06-07T08:02:35+00:00

public function get_children($id) { $query = $this->db->query(SELECT @last_id := id AS id, parent_id, FIO,

  • 0
public function get_children($id)
{
        $query = $this->db->query("SELECT 
          @last_id := id AS id,
          parent_id,
          FIO,
          @depth := IF(parent_id = ".$id.", 1, @depth + 1) AS depth,
          @first := IF(id = ".$id.", 'first', null) AS first
          FROM 
          users 
          FORCE INDEX (index_parent_id, PRIMARY, index_both),
          (SELECT @last_id := ".$id.", @depth := -1) vars
          WHERE id = ".$id." OR parent_id = @last_id OR parent_id = ".$id."
          ");

    return $query;

}

How can i increase the level depth of children nodes using the adjacent-model-list and this query, by now it gives me the root parent(selected by id in the function) and their children, but not deeper, any ideas?

foreach($query->result() as $q){


    if($q->first == 'first')
    {
        $parent_id = $q->parent_id;
        break;
    }


}
function print_list($array, $parent=0) {
        print "<ul>";
        foreach ($array as $row) {
            if ($row->parent_id == $parent) {
                print "<li>$row->FIO";
                print_list($array, $row->id);  # recurse
                print "</li>";
        }   }
        print "</ul>";
    }
echo print_list($query->result(), $parent_id);

then I render it in the view file…please help or any advices about what to change or see to increase the depth of the mysql query.

  • 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-07T08:02:37+00:00Added an answer on June 7, 2026 at 8:02 am

    I’m not sure about the schema of the database, but this is basically a stripped down version of something you might be looking for. Basically, you’ll need a function that calls itself, but the argument changes.

    In this case, it looks for users with parent_id = $parent_id (assuming the parent_id of the root is 0) lists then, and for each of the users, it looks for other users with parent_id = $id (where $id is their id) so basically, you have infinite depth

    <?
    function print_list($parent_id) {
        $query = "SELECT * FROM users WHERE parent_id=".$parent_id;
    
        print "<ul>";
        foreach($query->result() as $q) {
            $id = $q->id;
            print "<li>";
                print $q->FIO;
            print "</li>";
            print_list($id); //Here, it calls itself again
        }
        print "</ul>";
    }
    print_list(0); //Assuming the root-parent-id number is 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider: public function & get($name, $default = null) Why & ?
I have this code to get the default constructor: Public Function f(ByVal t As
I have this in my Controller. public function delete($id) { if($this->request->is('get')) { throw new
I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
public function create($tableName, $userInput) { $this->db->insert($tableName, $userInput); return $this->db->affected_rows(); } As you see, $this->db->affected_rows();
public function getItemsCollection($useCache = true) { if (is_null($this->_items)) { $this->_items = Mage::getModel('sales/quote_item')->getCollection(); $this->_items->setQuote($this); }
public function __construct($input = null) { if (empty($input)){ return false; } and then there's
There is probably something dumb I am doing wrong here. public function get_scores($id) {
public function action_adicionar_item() { $lista_item_pedido = array(); $x = 0; if(Session::has('lista_item_pedido')) { foreach(Session::get('lista_item_pedido') as
Is there a way to get the following function declaration? public bool Foo<T>() where

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.