0
我已經多層次的父子關係,我想列出它們在樹上structure.I也象ID字段的表,parent_id.I試圖像列表親子樹結構
$sql = 'SELECT * FROM list WHERE parent_id = 0';
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_array($result)) {
echo $row['id'].'<br>';
$child1_sql = "SELECT * FROM list WHERE parent_id = ".$row['id'];
$result1 = mysql_query($child1_sql, $link);
while ($row1 = mysql_fetch_array($result1)) {
$id = my_recursive_function($row1['parent_id'],$link);
echo $id;
}
}
function my_recursive_function($parent_id,$link) {
$child2_sql = "SELECT * FROM list WHERE parent_id = ".$parent_id;
$result2 = mysql_query($child2_sql, $link);
$row_cnt = mysql_num_rows($result2);
if($row_cnt > 0) {
while ($row = mysql_fetch_array($result2)) {
if($row['parent_id'] == 0) {
return $row['id'];
} else {
my_recursive_function($row['parent_id'],$link);
}
}
}
}
但給我
Fatal error: Out of memory (allocated 126877696) (tried to allocate 24 bytes)
嘗試增加內存限制:函數ini_set( 'memory_limit的', '128M'); – 2014-10-11 05:39:31
我認爲這不是解決方案,因爲我已經改變了它。 – Gautam3164 2014-10-11 05:40:28
然後你必須優化你的腳本:) – 2014-10-11 05:41:09