Привет, у меня есть данные ниже таблицы
id parent_id name
1 Machine
2 3 Ram
3 4 Cpu
4 Computer
5 6 food1
6 food2
Мне нужно выбрать возможных родителей
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 .
Как я пишу функцию (php, mysql recursive) в классе. Примечание: - Используйте только одну функцию Помогите мне Заранее спасибо.
У меня такая же проблема
тест класса {
public static $roleIds;
доступна публичная функцияParents() { 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;
}
}
он будет работать нормально, если мы используем одно время
если ситуация такая $ role//созданный объект с id 1
$ролевые > availableParents()
$role//созданный объект с id 2 $ Ролевые > availableParents()
$role//созданный объект с id 3 $ Ролевые > availableParents()
мы не получим правильный ответ (первые строки также изменят вторую модель).