lilwing Posted July 22, 2008 Share Posted July 22, 2008 I was reading this tutorial: http://www.finalwebsites.com/tutorials/dynamic-navigation-list.php I set up the database and everything, did the tutorial, and when I try to execute, I get unexpected $end. I have a feeling that is not the only error in the tutorial. I'd rather just be referenced to a better tutorial, if available, but if you could help me figure out what is wrong, it is greatly appreciated. Help! <?php $sql = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC"; $items = mysql_query($sql); while ($obj = mysql_fetch_object($items)) { if ($obj->parent_id == 0) { $parent_menu[$obj->id]['label'] = $obj->label; $parent_menu[$obj->id]['link'] = $obj->link_url; } else { $sub_menu[$obj->id]['parent'] = $obj->parent_id; $sub_menu[$obj->id]['label'] = $obj->label; $sub_menu[$obj->id]['link'] = $obj->link_url; $parent_menu[$obj->parent_id]['count']++; } } mysql_free_result($items); function dyn_menu($parent_array, $sub_array, $qs_val = "menu", $main_id = "nav", $sub_id = "subnav", $extra_style = "foldout") { $menu = "<ul id=\"".$main_id."\">\n"; foreach ($parent_array as $pkey => $pval) { if (!empty($pval['count'])) { $menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n"; } else { $menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n"; } if (!empty($_REQUEST[$qs_val])) { $menu .= "<ul id=\"".$sub_id."\">\n"; foreach ($sub_array as $sval) { if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent']) { $menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\">".$sval['label']."</a></li>\n"; } } $menu .= "</ul>\n"; } } $menu .= "</ul>\n"; return $menu; } foreach ($parent_array as $pkey => $pval) { if (!empty($pval['count'])) { $menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n"; } else { $menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n"; } if (!empty($_REQUEST[$qs_val])) { $menu .= "<ul id=\"".$sub_id."\">\n"; foreach ($sub_array as $sval) { if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent']) { $menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\">".$sval['label']."</a></li>\n"; } } $menu .= "</ul>\n"; } function rebuild_link($link, $parent_var, $parent_val) { $link_parts = explode("?", $link); $base_var = "?".$parent_var."=".$parent_val; if (!empty($link_parts[1])) { $link_parts[1] = str_replace("&", "##", $link_parts[1]); $parts = explode("##", $link_parts[1]); $newParts = array(); foreach ($parts as $val) { $val_parts = explode("=", $val); if ($val_parts[0] != $parent_var) { array_push($newParts, $val); } } if (count($newParts) != 0) { $qs = "&".implode("&", $newParts); } return $link_parts[0].$base_var.$qs; } else { return $link_parts[0].$base_var; } } ?> Link to comment https://forums.phpfreaks.com/topic/116045-dynamic-navigation-tutorial-errors/ Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 Find the missing ) ] } in there. Usually that error means a bracket wasn't closed. Link to comment https://forums.phpfreaks.com/topic/116045-dynamic-navigation-tutorial-errors/#findComment-596712 Share on other sites More sharing options...
lilwing Posted July 22, 2008 Author Share Posted July 22, 2008 Yeah I figured it was a bracket syntax error... but I am not sure where to put it; the tutorial doesn't say if I should leave the loop open to include another loop, or close it after the loop. I put a bracket in after the loop: foreach ($parent_array as $pkey => $pval) { I get the following errors: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\WebServer\wamp\www\linkstest.php on line 108 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\WebServer\wamp\www\linkstest.php on line 119 Warning: Invalid argument supplied for foreach() in C:\WebServer\wamp\www\linkstest.php on line 143 Link to comment https://forums.phpfreaks.com/topic/116045-dynamic-navigation-tutorial-errors/#findComment-596714 Share on other sites More sharing options...
lilwing Posted July 22, 2008 Author Share Posted July 22, 2008 Find the missing ) ] } in there. Usually that error means a bracket wasn't closed. Alright, I have the error down to one, and I have no idea what to do: Warning: Invalid argument supplied for foreach() in C:\WebServer\wamp\www\linkstest.php on line 143 It's talking about this: foreach ($parent_array as $pkey => $pval) { if (!empty($pval['count'])) { $menu .= " <li><a class=\"".$extra_style."\" href=\"".$pval['link']."?".$qs_val."=".$pkey."\">".$pval['label']."</a></li>\n"; } else { $menu .= " <li><a href=\"".$pval['link']."\">".$pval['label']."</a></li>\n"; } if (!empty($_REQUEST[$qs_val])) { $menu .= "<ul id=\"".$sub_id."\">\n"; foreach ($sub_array as $sval) { if ($pkey == $_REQUEST[$qs_val] && $pkey == $sval['parent']) { $menu .= "<li><a href=\"".rebuild_link($sval['link'], $qs_val, $sval['parent'])."\">".$sval['label']."</a></li>\n"; } } $menu .= "</ul>\n"; } } Link to comment https://forums.phpfreaks.com/topic/116045-dynamic-navigation-tutorial-errors/#findComment-596723 Share on other sites More sharing options...
lilwing Posted July 22, 2008 Author Share Posted July 22, 2008 Anyone?... ...I'll give you a blow job Link to comment https://forums.phpfreaks.com/topic/116045-dynamic-navigation-tutorial-errors/#findComment-596740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.