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

  • Home
  • SEARCH
  • 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 1043439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:40:01+00:00 2026-05-16T15:40:01+00:00

I am playing around with a code example i found here about ‘tree menu’

  • 0

I am playing around with a code example i found here about ‘tree menu’ and wanted to make this question.

function tree($id)
{
$query = "SELECT `name`,`id` from `table` WHERE `id_parrent` = '$id'";
$result = mysql_query($query);
 if(mysql_num_rows($result) != 0)
   {
        echo "<ul>";
        while($row = mysql_fetch_array($result))
        {             
             echo "<li>",$row[name],"</li>";
             tree($row[id]);
        }
        echo "</ul>";
   }
}

what if i want to display items in a way like this:

<ul>
<li>item 1</li>
<li>item 2</li>
  <li style="padding-left:10px;">item 3-has parent 2</li>
   <li style="padding-left:20px;">item 4-has parent 3</li>
  <li style="padding-left:10px;">item 5-has parent 2</li>
<li>item 6</li>
</ul>

My main problem is to find the level somehow so that i could multiply level*padding and create my list.
Any suggestions would be appreciated.

  • 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-05-16T15:40:01+00:00Added an answer on May 16, 2026 at 3:40 pm

    You need your tree function to track the level, and then apply padding if the level is greater than 1.

    function tree($id, $level=1) {
        $query = "SELECT `name`,`id` from `table` WHERE `id_parrent` = '$id'";
        $result = mysql_query($query);
        if (mysql_num_rows($result) != 0) {
         echo "<ul>";
         while ($row = mysql_fetch_array($result)) {
             if ($level == 1)
                 echo "<li>" . $row[name] . "</li>";
             else
              echo "<li style='padding-left: " + (($level - 1) * 10) + "px;'>" . $row[name] . "</li>";
             tree($row[id], $level + 1);
         }
         echo "</ul>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was playing around with some chrome extensions and I found this example: http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/pageaction_by_url/
I am playing around with the example from here ; esp. I have this
I been playing around with my code and I wanted to see what would
I was playing around with some Javascript snippets today and noticed that this code
Here is some C++ code I'm playing around with: #include <iostream> #include <vector> #define
Just playing around with memcache for the first time; here's my code: $memcache =
I am playing around with WPF a bit. Here is the Code that does
might be a silly question nonetheless: I'm playing around with the following code: $a='a';
I was playing around with some JavaScript code and found that when I took
I'm playing around with code like this: <s:Button id=test label=test transformX={Math.floor(test.width/2)} rotationY=20 x=20 y=20

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.