473,224 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Tree array

Hi,

I have a simple problem, but I don't found a solution for my problem.
I'm try, try and not found. If anybody help me, I very, very thankful
for this help.

Here is my problem:

I have a table with following data I have access:

page_id
page_path
page_depth
page_order
page_has_childs
page_title

I make chages add this fields to make a breadcrumbs functionality from
this system in the following fields I have stored this data:

page_id page_path page_depth page_order page_has_childs
page_title
1 x 1 0 1 Home
2 x.1 2 0 1 Products
3 x.1 2 2 0 3D Cad
9 x.1.2 3 2 0 Contact
10 x.1.2 3 0 0 Knowledge

In page path I store the location from that row data, for example in
page_id 10, I have the following path x(Home), 1(Products) and
2(Knowledge). In breadcrumbs I'm show like this Home > Products >
Knowledge.

My problem is, I need make a array tree with all data from database to
make a website map. anybody help me with this?

Thanks so much.

Leonardo da Silva Calado

May 30 '06 #1
4 2816
le*************@gmail.com said the following on 30/05/2006 12:13:

I make chages add this fields to make a breadcrumbs functionality from
this system in the following fields I have stored this data:

page_id page_path page_depth page_order page_has_childs
page_title
1 x 1 0 1 Home
2 x.1 2 0 1 Products
3 x.1 2 2 0 3D Cad
9 x.1.2 3 2 0 Contact
10 x.1.2 3 0 0 Knowledge

In page path I store the location from that row data, for example in
page_id 10, I have the following path x(Home), 1(Products) and
2(Knowledge). In breadcrumbs I'm show like this Home > Products >
Knowledge.


I'm not sure I understand your page_path system. Why does 1 mean
"Products" and 2 mean "Knowledge"?

The way I would do it is for each page, store the ID of its "parent", i.e.:

page_id parent_id title
---------------------------------
1 NULL Home
2 1 Products
3 1 3D Cad
9 2 Contact
10 2 Knowledge

That way, you can read the entire table into a PHP array, and then step
through the array to build up a tree data structure.
--
Oli
May 30 '06 #2
In the system information is stored to make a breadcrumbs site
functionality, page_path stores de location in breadcrumbs from page.
For example: page_id 9 "Contact" have 2 levels of depht to home. It's
make the following breadcrumb Home > Products > Contact

May 30 '06 #3
Rik
le*************@gmail.com wrote:
In the system information is stored to make a breadcrumbs site
functionality, page_path stores de location in breadcrumbs from page.
For example: page_id 9 "Contact" have 2 levels of depht to home. It's
make the following breadcrumb Home > Products > Contact


Which is still possible, using Oil's table.

I'm making a trail here, allthough with the build of the array this is
totally unnecessary:

function create_tree($parent=null, $depth=0, $trail='x' ){
$return = array();
$result = mysql_query("SELECT page_id, page_order, page_title
FROM table
WHERE page_parent='$parent'
ORDER BY page_order");
if(mysql_num_rows($result) > 0){
while($row = mysql_fetch_assoc($result)){
$return[$row['page_id']] = $row;
$return[$row['page_id']]['depth'] = $depth;
$return[$row['page_id']]['trail'] = $trail;
$childs =
create_tree($row['page_id'],$depth+1,$trail.'.'.$row['page_id']);
if(!empty($childs)){
$return[$row['page_id']]['childs'] = $childs
}
}
}
return $return;
}

$tree = create_tree();

function create_html_list($array){
if(!is_array($array)) return '';
$return = '<ul>';
foreach($array as $row){
$return .="<li>{$row['page_title']}";
if(isset($row['childs'])&&is_array($row['childs']){
$return .= create_html_list($row['childs']);
}
$return .='</li>';
}
$return = '</ul>';
return $return;
}

echo create_html_list($tree);

haven't tested the code, so maybe some debugging is in order.

Grtz,
--
Rik Wasmus
May 30 '06 #4
le*************@gmail.com wrote:
In the system information is stored to make a breadcrumbs site
functionality, page_path stores de location in breadcrumbs from page.
For example: page_id 9 "Contact" have 2 levels of depht to home. It's
make the following breadcrumb Home > Products > Contact


Leonardo,

I understand how you have it set up. However, the way Oli proposes will be much
easier to handle in the long run.

Your way means a lot of parsing of values, maintaining synchronization between
fields and a lot of other extra effort.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
7
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
7
by: Casper | last post by:
In scanning a drive and comparing file content, I need to remember filepaths to every single file I encounter so I can take actions on certain files later on. Rather than having a huge list...
2
by: Mriganka | last post by:
I want to create a hierarchical tree from the array of strings obtained by extracting a jar file.I want to do this using Javascript. For ex, I am having the entries in the array as...
3
by: tsunami | last post by:
hi all; I have an array and want to insert all the elements from this array to a binary search tree.That array is an object of the class of a stringtype which includes overloaded "< > = =="...
13
by: hornedw | last post by:
I have been working on a ecommerce website for myself. What I needed some assistance on was when i was trying to display the categories/subcategories for the different products. I decided to use...
8
by: ashore | last post by:
Folks, any url's around re subject matter? Performance isn't necessarily a problem, and the depth will be under, say, twenty. Thanks, all. --AS
2
by: uche | last post by:
Guys, I am trying to build a Parse Tree with the following grammar. I have implemented my insertions using a standard binary tree inserting algorithm. With the psuedocode below, can you guys...
2
by: Bart Kastermans | last post by:
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote: Thanks for the idea. I would expect the separation to lead to somewhat...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.