PHP unlimited class query parent layer function. ClassIDclassFIDclassNameclassCount10 China 021 Zhejiang 031 Jiangsu 042 Hangzhou 054 Xihu District 0 if findFather () show Hangzhou findFather () show Zhejiang findFa classFID className classCount
1 0 China 0
2 1 Zhejiang 0
3 1 Jiangsu 0
4 2 Hangzhou 0
5 4 Xihu District 0
If
FindFather (4, 0) display => Hangzhou
FindFather (4, 1) display => Zhejiang
FindFather (4, 2) display => China
FindFather () display => China-> Zhejiang-> Hangzhou
The code is as follows:
// =========== FindFather function START ==============
// Function: unlimitedly classify to find relevant data of the parent layer
// Parameter: $ classID, ID of the current child layer
// $ Type, 0 find yourself 1 Find Father 2 find ancestor 3 find Genealogy
// Field: primary key of the classID, which is the parent ID of the automatically generated classFID.
// ClassName category name classCount category Statistics
Function findFather ($ classID, $ type)
{
Global $ db, $ flist, $ forefather;
Define ("_ STR_CUT", "-> ");
$ Db-> query ("set names utf8 ");
$ SQL = select * from tbl_name where classID = ". $ classID .";
$ Result = $ db-> query ($ SQL );
$ RecordCount = $ result-> num_rows;
Http://www.bkjia.com/PHPjc/486519.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486519.htmlTechArticleclassID classFID className classCount 1 0 China 0 2 1 Zhejiang 0 3 1 Jiangsu 0 4 2 Hangzhou 0 5 4 Xihu District 0 if findFather () show = Hangzhou findFather) show = Zhejiang findFa...