I have a rather difficult bug. The following function is a recursive script designed to retrieve layers of navigation.
//recursive function to set higher level navigation tree
function subLevels ($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 //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."navigation 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']; } } }
//create current layer
foreach ($part_tree['children'] as $key => $child_string) {
if (!empty ($child_string)) { $temp_array = explode ("|", $child_string); $part_tree['children'][$key] = $temp_array; } }
//see if a new layer is required for each child 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]);
}
}
return $part_tree;
}//function
and I am fairly confident this is the buggy section
//set new layer if initive if (empty ($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."navigation 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']; } } }
The nature of the problem is this: as soon as I finished the above section, the server started returning error 500. Specifically, once I finished the code that populates $part_tree['children'][$variable_name] I immediately hit the problem.
It is only with that array element set that the rest of the function will work. On the first iteration it is provided in the correct format and is re-populated here for each subsequent layer of navigation.
My only thought for a solution was that I was recusing too deep and the server didn't like it. I reduced the navigation table so any given root level leads to a maximum of 3 others, meaning the function runs 3 times, but this has not been successful. Prior to this I have been testing with unlimited levels of recursion problem free.
If anyone could offer an alternative reason for this 500 error I'm all ears.
After activating the error flagging the site returned these messages:
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
and this one over and over:
Notice: Array to string conversion in /mnt/sw/2028751/web_applications/web/project_site/secure_includes/modules/navigation/class.php on line 91
I find this bizarre as the only file I have been working on is navigation/class.php.
-
you should as well have a look at recursive queries, or if you use MySQl search for "nested set" queries, and avoid hard job on PHP when the SQL server can do a big part of the job.regilero– regilero01/15/2011 13:58:39Commented Jan 15, 2011 at 13:58
-
I will be looking at that idea for sureYsoL8– YsoL801/15/2011 14:50:00Commented Jan 15, 2011 at 14:50
1 Answer 1
First can you try to enable error reporting using the following PHP code:
ini_set('display_errors','On');
error_reporting(E_ALL);
I remember a previous question where that seeemed to help a lot.
That can help narrow it down or specify the root cause (or in some cases, fix it all together). Let me know how that goes and I'll keep helping.
-
I'll be looking at this again tomorrow so if you could look here then, that would be great.YsoL8– YsoL801/14/2011 20:54:07Commented Jan 14, 2011 at 20:54
-
Sure, just leave a comment so it shows up in my inbox. I should be around.rownage– rownage01/14/2011 20:55:19Commented Jan 14, 2011 at 20:55
-
See my edit for what happened when I switched on error reportingYsoL8– YsoL801/15/2011 12:24:19Commented Jan 15, 2011 at 12:24