循环接收物品

时间:2014-02-22 19:42:17

标签: php mysql

分组数据库结构

id | parent_id |名称

示例数据

   id | parent_id | name
    3 | 2         | group1
    4 | 3         | group2
    5 | 4         | group3
    6 | 4         | group4

期望的结果

3, 4, 5, 6   ( -  these groups have group1 )

代码

$CurrentGroup = 3;
$query = mysql_query('SELECT id FROM groups WHERE parent_id = ' . $CurrentGroup);
// I get IDS for subgroups of Group(3)
foreach ($query as $value) $ids[] = $value['id']; 
// just need to get all subgroups $ids used and their subgroups

需要通过添加添加了parent_id的子组(添加子组的Id组)来获取数据库中所有子组及其子组的列表。子组可以在sub

0 个答案:

没有答案