You can help me to see how this code cannot retrieve the root category ID!

Source: Internet
Author: User
Let me see how this code cannot retrieve the root category ID! Urgent! /* & Nbsp; * obtain the root category based on the subclass ID & nbsp; */functionget_root_class ($ classId) {global $ db, $ lot_array; $ class = $ db-& gt; fe, please help me see how this code cannot retrieve the root category ID! Urgent!
/*
* Obtain the root category based on the subclass ID.
*/
Function get_root_class ($ classId ){
Global $ db, $ lot_array;
$ Class = $ db-> fetch_first ("SELECT pid, name FROM new_infor_class WHERE id = $ classId ");
If ($ class ['pid']! = 0 ){
Get_root_class ($ class ['pid ']);
} Else {
Return $ class ['name'];
}
}
The category is set according to the infinite classification, so the returned category name is $ classId. I really don't understand it! Which eldest brother can help me!

------ Solution --------------------
Okay, just set up a test environment.
SQL code
---- TABLE structure 'tree' -- create table if not exists 'tree' ('id' int (11) not null AUTO_INCREMENT, 'pid 'int (11) default null, 'name' varchar (10) default null, primary key ('id') ENGINE = MyISAM default charset = latin1 AUTO_INCREMENT = 5; ---- data 'tree' in the table to be stored -- insert into 'tree' ('id', 'pid ', 'name') VALUES (1, 0, 'A '), (2, 1, 'B'), (3, 2, 'C'), (4, 3, 'D ');

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.