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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:22:11+00:00 2026-06-07T00:22:11+00:00

this is the mysql query SELECT * FROM users AS up JOIN users AS

  • 0

this is the mysql query

SELECT * 
FROM users AS up
JOIN users AS u ON up.id = u.parent_id
JOIN users AS uc ON u.id = uc.parent_id
WHERE up.id =16

and this is the output in the view file

   <?php foreach($query->result() as $q): ?>
    <?php echo $q->id; ?>

    <?php endforeach; ?>

the mysql result gives 3 levels of result, but in html it outputs only 1 level, and is the last level, but i need to render it in a hierarchy

  • 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-07T00:22:12+00:00Added an answer on June 7, 2026 at 12:22 am

    Change your query to:

    SELECT up.id AS id1, u.id AS id2, uc.id AS id3
    FROM users AS up
    JOIN users AS u  ON up.id =  u.parent_id
    JOIN users AS uc ON  u.id = uc.parent_id
    WHERE up.id = 16
    

    Then you can access the three levels as id1, id2 and id3:

    <?php
      foreach($query->result() as $q) {
        echo $q->id1;
        echo $q->id2;
        echo $q->id3;
      }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MySQL query like this: SELECT MAX(messages.ID) as maxID, messages.from, messages.read, users.userName
I'm trying this: $result = mysql_query( SELECT Users.*, Posts.* FROM Users INNER JOIN Posts
So, I have this mysql query: SELECT member_id, text FROM review WHERE text !=
I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT
I have a mysql query like this: $topicreplycount = mysql_query('SELECT COUNT(DISTINCT post_msg_id) FROM phpbb_attachments
I've used this MySQL query to get data: SELECT DISTINCT A.*, B.username FROM posts
I've got a mysql query like this: SELECT A.ID, A.NAME, B.ID, B.NAME FROM table1
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,
In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
$threadID=$_GET['threadID']; $result=mysql_query( SELECT * FROM threads AS Threads INNER JOIN users AS Users ON

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.