Unix Technical Forum

Generic MySQL/PHP Tree Schema?

This is a discussion on Generic MySQL/PHP Tree Schema? within the MySQL forums, part of the Database Server Software category; --> Folks, any url's around re subject matter? Performance isn't necessarily a problem, and the depth will be under, say, ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:49 AM
ashore
 
Posts: n/a
Default Generic MySQL/PHP Tree Schema?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:49 AM
ZeldorBlat
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

On May 14, 12:52 pm, ashore <shor...@gmail.com> wrote:
> 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


<http://www.google.com/search?q=sql+tree+structure>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:50 AM
Tyno Gendo
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

ZeldorBlat wrote:
> On May 14, 12:52 pm, ashore <shor...@gmail.com> wrote:
>> 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

>
> <http://www.google.com/search?q=sql+tree+structure>
>


If you're looking to create a menu type tree you need to look into
recursion, i use a function like below, not saying this is the best as
I'm a newbie but it work and creates a menu tree, I then use another
function to parse this tree into the format i need (usually html) using
another similar recursing function.

public function makeTree( $menu_seq, $depth ) {

$sql = "SELECT * FROM menu WHERE menu_parent=" . $menu_seq . "
ORDER BY menu_dspseq ASC;";
$ds = mysql_query( $sql ) or die(mysql_error());
if (mysql_num_rows($ds)>0) {
while ( $dr = mysql_fetch_assoc($ds) ) {
$sql = "SELECT COUNT(menu_seq) FROM menu WHERE
menu_parent = " . $dr['menu_seq'];
$dsc = mysql_query($sql);
$drc = mysql_fetch_array($dsc);
$array[$dr['menu_seq']]['menu_text'] =
htmlentities($dr['menu_text']);
$array[$dr['menu_seq']]['menu_parent'] =
$dr['menu_parent'];
$array[$dr['menu_seq']]['menu_page'] =
$dr['menu_page'];
$array[$dr['menu_seq']]['depth'] = $depth;
if ($drc>0) {
$array[$dr['menu_seq']]['children'] =
$this->makeTree( $dr['menu_seq'], $depth+5 );
} else {
$array[$dr['menu_seq']]['children'] = null;
}
}
mysql_free_result($ds);
}
return (isset($array) ? $array : false);

}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:51 AM
ashore
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

Thanks, all - yr responses are appreciated.

Now, answering my own posting in case others are following this
thread: Do take a look at

http://freshmeat.net/projects/nodetree/

Pretty good, actually.

-AS

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:52 AM
Aerik
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?


>
> If you're looking to create a menu type tree you need to look into
> recursion, i use a function like below, not saying this is the best as
> I'm a newbie but it work and creates a menu tree, I then use another
> function to parse this tree into the format i need (usually html) using
> another similar recursing function.
>



I think if you're going to have any kind of volume and depth at all,
it's probably better to stay away from recursive solutions, since you
could end up with an awful lot of queries per page load. Of course,
you could use caching or something to minimize this, but... I like
outline style solutions, where you keep all your data in one table and
have one column that keeps some data outline style ("1.12.5" or
similar) It looks like that nodetree project uses soemthing like
this...

Aerik

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:52 AM
ashore
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

The application area I have in mind here is a crisis management/
tracking/dispatch operation, in which there's a hierarchy of component
steps comprising the collection of responses. (Ex: a storm, in which
roads, bridges, waterways, telecommunications facilities, hospitals,
etc., are affected, with distinct problems associated with each.)

Kind of like a work breakdown structure, but somewhat more dynamic. I
looked at some project management applications, but a cursory scan
showed nothing like what we're discussing here -- although I can't
imagine we're breaking new ground.

-AS

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 09:52 AM
John Nagle
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

ashore wrote:
> The application area I have in mind here is a crisis management/
> tracking/dispatch operation, in which there's a hierarchy of component
> steps comprising the collection of responses. (Ex: a storm, in which
> roads, bridges, waterways, telecommunications facilities, hospitals,
> etc., are affected, with distinct problems associated with each.)
>
> Kind of like a work breakdown structure, but somewhat more dynamic. I
> looked at some project management applications, but a cursory scan
> showed nothing like what we're discussing here -- although I can't
> imagine we're breaking new ground.


It's ancient technology, but look at MUMPS, the Massachusetts
General Hospital system from the 1970s.

John Nagle
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 09:52 AM
maruerru
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

On 14 Mai, 18:52, ashore <shor...@gmail.com> wrote:
> 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


Look at this: "Managing Hierarchical Data in MySQL" (
http://dev.mysql.com/tech-resources/...ical-data.html )

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 09:52 AM
ashore
 
Posts: n/a
Default Re: Generic MySQL/PHP Tree Schema?

Perfect! Thanks,

-AS

On May 21, 6:50 am, maruerru <m...@mrumpf.de> wrote:
>
> Look at this: "Managing Hierarchical Data in MySQL" (http://dev.mysql.com/tech-resources/...ical-data.html)



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com