, my little brother, I have an infinite category tree menu table in the background, little brother I call this table in the foreground, how to call out the series

Source: Internet
Author: User
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
(
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.