>>>>> "Hengky" == Hengky <[EMAIL PROTECTED]> writes:
Hengky> hi all, Hengky> i'm working on database with a lot of category... Hengky> here i example for category that i like to create Hengky> Computer Hengky> Computer/Motherboard Hengky> Computer/Motherboard/AMD Hengky> Computer/Motherboard/Intel Hengky> Computer/Drive & Storage Hengky> Computer/Driver & Storage/SATA Hengky> Computer/Driver & Storage/ATA Hengky> Computer/Driver & Storage/ATA/7200 RPM/ Hengky> Computer/Driver & Storage/ATA/10000 RPM/ Hengky> Elektronik Hengky> Elektronik/Television Hengky> Elektronik/Television/CRT Hengky> Elektronik/Television/CRT/14 " Hengky> and go on Hengky> so i use on mysql table Hengky> table Category Hengky> --------------------------------------- Hengky> | id_cat | nama_category | id_parent | Hengky> --------- ----------------- ----------- Hengky> | 001 | Computer | TLCAT | Hengky> | 002 | Motherboard | 001 | Hengky> | 003 | AMD | 002 | Hengky> | 004 | Intel | 002 | Hengky> | 005 | Drive & Storage | 001 | Hengky> | 006 | SATA | 005 | Hengky> | 007 | ATA | 005 | Hengky> | 008 | 7200 RPM | 007 | Hengky> | 009 | Elektronik | TLCAT | Hengky> | 010 | 10000 RPM | 007 | Hengky> | 011 | Television | 009 | Hengky> | 012 | CRT | 011 | Hengky> | 013 | 14" | 012 | Hengky> --------- ----------------- ----------- I'd do most of the work in Perl, unless you really like a lot of queries to the database. First pass: create mapping of: $cat{'001'}{name} = 'Computer'; push @{$cat{'TLCAT'}{kids}}, '001'; $cat{'002'}{name} = 'Motherboard'; push @{$cat{'001'}{kids}}, '002'; $cat{'003'}{name} = 'AMD'; push @{$cat{'002'}{kids}}, '003'; See the pattern? Do this for the entire database. Then walk it recursively to dump it: print "$_\n" for kids_of('TLCAT', ''); sub kids_of { my ($cat, $parent) = @_; my $path = "$parent/$cat{$cat}{name}"; return $path, # self map { kids_of($_, $path) } sort kids @{$cat{$cat}{kids}}; # kids } -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>