开发者

Is there PHP treeview with data from database?

I want to know if there exists php treeview with data from mysql. I haven't found a suitalbe one for my project. Do you know if there is some plugins or code samples out there?

Thanks a lot.

Edit:

jQuery Treeview's asyncronous example, link text

I found it can work, but i d开发者_JAVA百科on't know how to get the source.php. Do you have any ideas or other propositions?


you would need to run the query yourself, but it's pretty easy. the output the tree expects is an array of objects in json format like the example below.

your table structure could be:

tree_node (id, title, parent_id)

you would select the root node, then it's children, recursively until the tree is complete.

function expandTree($node)
{
  $result = array('text' => $node['title'], 'children' => array());
  $nodes = getChildren($node);  // query all nodes whose parent_id = $node['id']
  foreach ($nodes as $node) {
    $result['children'][] = expandTree($node);
  }
  return $result;
}

output format:

[
{
    "text": "1. Pre Lunch (120 min)",
    "expanded": true,
    "classes": "important",
    "children":
    [
        {
            "text": "1.1 The State of the Powerdome (30 min)"
        },
        {
            "text": "1.2 The Future of jQuery (30 min)"
        },
        {
            "text": "1.2 jQuery UI - A step to richnessy (60 min)"
        }
    ]
},
{
    "text": "2. Lunch  (60 min)"
},
[...]


Assuming you have a db with parents and children, have a look at

http://www.ideashower.com/our_solutions/create-a-parent-child-array-structure-in-one-pass/ & http://www.phpriot.com/articles/nested-trees-1

Once you have your data correctly sorted, you can then look at rendering it.


To present bulk of data with parent child relationship Treeview is a classical approach. The major advantage of Treeview is using a Treeview we can show more data in less space. Assume that you have a global recruitment portal. You want to display job opportunities depending upon Countries and their Cities. In this case you required Treeview. Using a Treeview easily you can display Countries & related Cities. In this session let us share codes for a PHP Treeview using data from MySQL Database. In front-end using PHP I am binding data to ol li element of HTML. Then by applying CSS giving expand and collapse effects to the Treeview. Let us explain this PHP Treeview Example Step by Step. PHP Treeview Example using data from MySQL Database

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜