PHP City Unlimited Classification

Source: Internet
Author: User

PHP City Unlimited Classification

ClassID Classfid className ClassCount
1 0 China 0
2 1 Zhejiang 0
3 1 Jiangsu 0
4 2 Hangzhou 0
5 4 West L. District 0
If
Findfather (' 4 ', ' 0 ') shows => Hangzhou
Findfather (' 4 ', ' 1 ') shows => Zhejiang
Findfather (' 4 ', ' 2 ') shows => China
Findfather (' 4 ', ' 3 ') shows => China-> Zhejiang-> Hangzhou
The code is as follows:
Copy Code
========== findfather function START ==========
Function: To find the relevant data of the parent layer by the infinite level classification
Parameters: $classID, number of the current child layer
$type, 0 Find yourself 1 Find your Father 2 Find your ancestors 3 Find a family tree
Fields: ClassID primary keys, generating Classfid parent numbers from
ClassName category name ClassCount classified 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;
if ($recordCount!= 0)
{
Take value
$row = $result->fetch_assoc ();
$classFID = $row [' Classfid '];
$classID = $row [' ClassID '];
$className = $row [' ClassName '];

If the ancestor is found, that is, the Classfid is 0, the function state is set to 0
if ($classFID = = ' 0 ') $type = ' 0 ';
}

if ($type = = ' 1 ')//Find Father
{
$type = ' 0 '; The second start function state is 0, that is, the loop is 2 times
Findfather ($classFID, $type);
}
else if ($classFID!= ' 0 ' and $type = = ' 2 ')//Find ancestor, state type is 2, ancestor Classfid not 0 not found
{
Findfather ($classFID, $type);
}
else if ($type = = ' 3 ')
{
Findfather ($classFID, $type);
$flist = $flist. _str_cut. $className; Generating genealogy
}
else if ($type = = ' 0 ')
{
$forefather = $className;
}

        $result = $forefather. $flist;
        return $result;
        
    }

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.