For help, I have an infinite class tree menu table in the background, I call this table in the foreground, how to call out the series
This post was last edited by xiachao2008 on 2012-05-28 18:47:53
I'm going to implement it like this effect http://www.tmall.com/?spm=1.1000386.220593.1&TBG=146280.176778.1
I'm going to make it work like this.
What should I do, I did the following work
My background infinite classification tree table
CREATE TABLE IF not EXISTS ' www.dianxin.com '. ' Dx_gd_type ' (
' t_id ' INT (one) not NULL auto_increment COMMENT ' categorical id\n ',
' T_name ' VARCHAR (+) NULL COMMENT ' shopping name category \ n ',
' t_family_id ' varchar (one-to-one) not NULL default ' 00000000 ' COMMENT ' parent ID, top-level classification defaults to 0\n ',
' T_orders ' SMALLINT (5) NULL COMMENT ' shopping sort order \ n ',
' T_remark ' varchar (+) NULL COMMENT ' remark \ n ',
PRIMARY KEY (' t_id '))
ENGINE = MyISAM DEFAULT Charset=utf8
COMMENT = ' Dim sum shopping type Table \ n ';
Note: The t_family_id is classified like this, (the number that is stored is the following law)
10 representative clothes
20 on behalf of digital
30 Stands for Furniture
Level Two classification
1001 for Men's Clothing
1002 on behalf of women's clothing
Level Three classification
100201 on behalf of women's underwear
100202 on behalf of women ...
How do I write this calling code to achieve an effect like this?
Share to: more
------Solution--------------------
This post was last edited by xuzuning on 2012-05-28 19:18:23
It's easy to get such an array from the database
$ar = Array (
Array (' 10 ', ' on behalf of clothes '),
Array (' 20 ', ' on behalf of the digital '),
Array (' 30 ', ' stands for furniture '),
Array (' 1001 ', ' on behalf of men's clothing '),
Array (' 1002 ', ' on behalf of women's clothing '),
Array (' 100201 ', ' on behalf of women's underwear '),
Array (' 100202 ', ' on behalf of women ... '),
);
Break down the hierarchy of classifications
$r = Array ();
foreach ($ar as $v) {
$p =& $r;
foreach (Str_split (Array_shift ($v), 2) as $k) {
if (! isset ($p [$k])) $p [$k] = array ();
$p =& $p [$k];
}
$p [' value '] = $v;
}
Print_r ($R);
Get an array like this, then it's too easy.
array
(
[ten] = = Array
(
[value] = array
(
[0] = = Clothes
)
[] = + Array
( br> [value] = Array
(
[0] = = Men's Clothes
)
)
[Geneva] = + Array
(
[value] = Array
(
[0] = = Women's clothing
[%] = Array
(