Let me see how this code does not get the root classification of the id!

Source: Internet
Author: User
Let's see how this code doesn't get the root classification id!. Tokyu
/*
* Get root classification based on 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 '];
}
}
Classification is set according to the infinite classification, so return is $CLASSID classification name, really do not understand! Who's the big Brother to help me!

------Solution--------------------
Okay, just a test environment.
SQL Code
Structure of the----table ' tree '--create table IF not EXISTS ' tree ' (  ' id ' int (one) not NULL auto_increment,  ' pid ' int (one) ' DEFAULT NULL,  ' name ' varchar (TEN) default NULL,  PRIMARY KEY (' id ')) engine=myisam  default Charset=latin1 auto_ increment=5;----Dump the data in the table ' tree '--insert into ' tree ' (' id ', ' pid ', ' name ') of 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.