用户表
在注册的时候每个用户都要放parent_id,谁注册在parent_id下面,所以我做了不同的表
赞助商表
然后像那样做树
我想像这样统计记录
所以请指导我如何计算这样的记录,或者我想说的是,对于这种计数,我必须更改数据库,在此先感谢
最佳答案
我在表中有邻接模型结构,所以我得到了非常好的解决方案 count user_id under parent_id
该函数统计 parent_id 下的 user_id
function display_children($parent, $level) {
$count = 0;
$result = mysql_query('SELECT user_id FROM sponsers '.'WHERE parent_id="'.$parent.'"');
while ($row = mysql_fetch_array($result))
{
$var = str_repeat(' ',$level).$row['user_id']."\n";
//echo $var after remove comment check tree
// i call function in while loop until count all user_id
$count += 1 +$this->display_children($row['user_id'], $level+1);
}
return $count; // it will return all user_id count under parent_id
}
调用函数
display_children(999, 0)
关于php - 统计php mysql中的多级营销(树)记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10477533/