473,503 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2831
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
7933
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
3612
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
2885
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
1745
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
2837
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
3854
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
2653
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
4417
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
2236
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
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.