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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:41:34+00:00 2026-06-01T05:41:34+00:00

-EDIT- <li> would probably be better but the same question still applies. So I

  • 0

-EDIT- <li> would probably be better but the same question still applies.

So I have everything working as far as I can display the data and get the expected results. The display portion I have is coming from the article at http://www.sitepoint.com/hierarchical-data-database-2/

I have:

$right = array();
    $show = "";
    while ($row = mysql_fetch_array($title)) {          
        if (count($right)>0) {
            while (count($right)>0&&($right[count($right)-1]<$row['rgt'])) {
                array_pop($right);
            } 
        }

        $show .= str_repeat('->',count($right)).$row['title'].count($right)."<br>";  
        $right[] = $row['rgt'];
    }
    return $show;

It works as expected. What I want to do now is enclose them properly in divs. So I want it to look something like:

<div>
  Title
  <div>
    subtitle
      <div>
        subsubtitle
      </div>
    </div>
</div>
<div>
  Title2
  <div>
    subtitle2
      <div>
        subsubtitle2
      </div>
    </div>
</div>

So you can see the top Title div encloses all the subs of that div and so on. I am not sure how to go about this. I can see that what I want to do is once count($right) is again equal to the count of the div is when to close the div, but again, not sure how to go about it.

  • 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-01T05:41:36+00:00Added an answer on June 1, 2026 at 5:41 am

    One approach is to organize the data into a structure that you can more easily iterate:

    $divs = array();
    while ($row = mysql_fetch_array($title)) {          
        $divs[$row['left']] = array('type'=>'open', 'text'=>$row['title']);
        $divs[$row['rgt']]  = array('type'=>'close');
    }
    
    $divCount = count($divs);
    for ($d=1; $d<$divCount; $d++) {
        if ($divs[$d]['type'] == 'open') {
            echo "<div>" . $divs[$d]['text'];
        } else {
            echo "</div>";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a stupid question but will ask anyway sine I have no
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use the django contrib.admin pages to edit my models, but
I would like to display certain meta data fields in the edit form based
I have a limited c++ background and I would like to edit the registry.
The question is in the title... I searched but couldn't find anything. Edit: I
This is probably my naivety showing through, but anyway... I have a generic interface
--edit -- Solved the question : a comment on the last sidenote would be
EDIT: I would really like to see some general discussion about the formats, their
I would like to edit matlab scripts in two cases (1) In matlab Command

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.