Recusive fonksiyonu

1 Cevap php

Merhaba aşağıda tablo verileri var

   id  parent_id  name
    1   	      Machine
    2    3	      Ram
    3    4	      Cpu
    4   	      Computer
    5     6        food1
    6              food2

Benim gerek olası anne seçmek için

    for example 
    1) if we select 'machine' all others can parents
    2) if we select 'cpu' then 'ram' and 'cpu' should not be there
    3) if we take 'food2' then 'food2', 'food1' should not be there all other have possibility .

How i write a (php,mysql recursive) function in a class . Note :- Only use single function Pls help me Thanks in advance .

1 Cevap

i aynı sorun var

class test {

public static $roleIds;

public function availableParents() { self::$roleIds = null;

    $discardRoleIds = implode(',',$this->unAvailableRoles());

    $parentRoles = Acl_Model_Role::fetchAll("id NOT IN ({$discardRoleIds}) AND isactive = true" );

    return $parentRoles;        
}

/**
 * Getting  not available role id
 * 
 * @author Linto
 * @since 2009-11-25
 * @return Array 
 */
public function unAvailableRoles()
{
    $where = "parent_id = {$this->getId()}"; 

    self::$roleIds[] = $this->getId();       

    $count = Acl_Model_Role::count($where);

    if($count != 0) {
        foreach(Acl_Model_Role::fetchAll($where) as $role){                   
            $role ->unAvailableRoles();                
        }         
    }
    return  self::$roleIds; 

}

}

Biz bir defa kullanabilirsiniz eğer, iyi çalışır

if situation is like this $role //created object with id 1

$ Rol> availableParents ()

$role //created object with id 2 $ Rol> availableParents ()

$role //created object with id 3 $ Rol> availableParents ()

(İlk satır da ikinci bir model değişecek.) doğru cevap almazsınız