【问题标题】:Recursive function gives 500 error at development conclusion递归函数在开发结束时给出 500 错误
【发布时间】:2011-01-14 18:19:04
【问题描述】:

我有一个相当困难的错误。以下函数是一个递归脚本,旨在检索导航层。

//递归函数设置更高 级别导航树
函数子级别 ($part_tree) {
// print_r($part_tree);

//set new layer if initive
if (empty ($part_tree['tree_name'])) {
  $grandchild_array = explode ("|", $part_tree['children'][0]);

T //用新层的正确子代填充主数组 foreach ($grandchild_array as $key => $array) { if (is_array($array)) {

    foreach ($array as $inner_key => $current_id) {
      $result = mysql_query("SELECT children FROM

".PRE."导航 WHERE id = '$current_id'");

      $row = mysql_fetch_array($result);

      $new_child[$current_id] = $row['children'];
    }

    foreach ($new_child as $new_id => $row) {

        $part_tree['children'][$new_id] = $row['children'];

      }

  } else {
  // echo $array;
   $result = mysql_query("SELECT children FROM ".PRE."navigation WHERE

id = '$array'");

   $row = mysql_fetch_array($result);

   $part_tree['children'][$array] = $row['children'];

  }
  }

}

//创建当前层

foreach ($part_tree['children'] as $key => $child_string) {

if (!empty ($child_string)) {
$temp_array = explode ("|", $child_string);
$part_tree['children'][$key] = $temp_array;
}   }

//查看是否需要新层 每个孩子 foreach ($part_tree['children'] as $key => $array) {

if (!empty ($array)) {
  $temp_string = implode ("|", $array);
  $part_tree['children'][$key]['children'][]

= $temp_string; $part_tree = $this -> subLevels ($part_tree['children'][$key]);

}

}

返回 $part_tree;

 }//function

我相当有信心这是有问题的部分

//如果是初始层,则设置新层 如果(空($part_tree['tree_name'])){ $grandchild_array = explode("|", $part_tree['children'][0]);

  //populate the main array with the correct children for the new layer
  foreach ($grandchild_array as $key => $array) {
  if (is_array($array)) {

    foreach ($array as $inner_key => $current_id) {
      $result = mysql_query("SELECT children FROM

".PRE."导航 WHERE id = '$current_id'"); $row = mysql_fetch_array($result); $new_child[$current_id] = $row['children']; }

    foreach ($new_child as $new_id => $row) {
        $part_tree['children'][$new_id] =

$row['孩子']; }

  } else {
  // echo $array;
   $result = mysql_query("SELECT children FROM ".PRE."navigation WHERE

id = '$array'"); $row = mysql_fetch_array($result);

   $part_tree['children'][$array] = $row['children'];

  }
  }

}

问题的本质是:当我完成上述部分后,服务器开始返回错误 500。具体来说,一旦我完成了填充 $part_tree['children'][$variable_name] 的代码,我立即点击问题。

只有使用该数组元素集,该函数的其余部分才能工作。在第一次迭代中,它以正确的格式提供,并在此处为每个后续导航层重新填充。

我唯一想到的解决方案是我回避太深,服务器不喜欢它。我减少了导航表,因此任何给定的根级别最多导致其他 3 个,这意味着该函数运行 3 次,但这并没有成功。在此之前,我一直在测试无限制的递归问题。

如果有人可以为这个 500 错误提供替代原因,我会全力以赴。

激活错误标记后,站点返回以下消息:

Notice: Undefined index: expire in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/users/index.php on line 32
Notice: Undefined property: user::$logged in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/users/class.php on line 153
Notice: Undefined property: user::$logged in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/users/class.php on line 153
Notice: Undefined index: expire_flag in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/preprocessor/index.php on line 29
Notice: Undefined variable: error404 in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/preprocessor/index.php on line 36

这个一遍又一遍:

Notice: Array to string conversion in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/navigation/class.php on line 91

我觉得这很奇怪,因为我一直在处理的唯一文件是 navigation/class.php。

【问题讨论】:

  • 你也应该看看递归查询,或者如果你使用 MySQl 搜索“嵌套集”查询,并且当 SQL 服务器可以完成大部分工作时避免在 PHP 上进行艰苦的工作.
  • 我肯定会考虑这个想法

标签: php recursion


【解决方案1】:

首先您可以尝试使用以下 PHP 代码启用错误报告:

ini_set('display_errors','On'); 
error_reporting(E_ALL); 

我记得 a previous question 这似乎很有帮助。

这可以帮助缩小范围或指定根本原因(或者在某些情况下,一起解决)。 让我知道情况如何,我会继续提供帮助。

【讨论】:

  • 我明天会再看这个,所以如果你能看这里,那就太好了。
  • 当然,只要发表评论,它就会显示在我的收件箱中。我应该在附近。
  • 查看我的编辑,了解我打开错误报告时发生的情况
猜你喜欢
  • 2021-11-14
  • 2021-11-16
  • 2014-06-26
  • 2015-07-27
  • 2013-06-18
  • 1970-01-01
  • 2021-05-14
  • 2020-02-19
  • 1970-01-01
相关资源
最近更新 更多