开发者

Dynamic Treeview PHP

开发者 https://www.devze.com 2022-12-17 12:04 出处:网络
I want to make a dynamic populated treeview from mysql database in PHP. I have searched a lot for that, but i haven\'t got the solution yet (jquery treeview seems not working in my context).

I want to make a dynamic populated treeview from mysql database in PHP. I have searched a lot for that, but i haven't got the solution yet (jquery treeview seems not working in my context).

And 开发者_StackOverflowi want to realize is that i extend the treeview by clicking the "+" sign.

When i click the item of the treeview, it will execute a query and display the result in the same page.

Do you know how to realize it?

Thanks in advance.


Try with <ul> <li> nesting. If level > 1, hide it with CSS and add + element. With JavaScript add event to + which will show you this nearby <ul> container.

Edit:

<ul>
  <li>
    <a href="#">+</a>
    Element A
    <ul class="hide">
      <li>Subelement AA</li>
      <li>Subelement AB</li>
      <li>Subelement AC</li>
    </ul>
  </li>
  <li>Element B</li>
    <a href="#">+</a>
    Element C
    <ul class="hide">
      <li>Subelement CA</li>
      <li>
        <a href="#">+</a>
        Subelement CB
        <ul class="hide">
          <li>Subelement CBA</li>
          <li>Subelement CBB</li>
          <li>Subelement CBC</li>
          <li>Subelement CBD</li>
        </ul>
      </li>
      <li>Subelement CC</li>
    </ul>
  <li>Element D</li>
</ul>


I have this functionality in my bespoke CMS.

I have one PHP function that simple queries the database and uses recursion. The first parameter passed to this function is the parent, which defaults to 0.

So when the function is called, it queries the database for all pages with a parent value of 0.

When looping over the result set, the function checks if there are any pages with a parent value of that page's ID. If so, it starts a new list and pulls records that are children of that particular page.

The above sets up a recursive function, which outputs a multiple-level <ul>. I then use a jQuery plug-in to transform this list into a file tree, with + / - icons to toggle branches and file type icons.

I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消