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 ');