doddsey_65 Posted December 23, 2010 Share Posted December 23, 2010 I have a foreach loop which shows the breadcrumb display. But it's stopped working. For some reason the links are no longer links. They are just echoed on screen with no <a> tags. setting up array: $crumb_query = mysqli_query($link, "SELECT f.forum_id, f.forum_cat_id, f.forum_name, c.cat_id, c.cat_name FROM ".TBL_PREFIX."forums as f LEFT JOIN ".TBL_PREFIX."categories as c ON c.cat_id = f.forum_cat_id WHERE f.forum_id = '$forum_id' ") or die(mysqli_error($link)); $crumb_info = mysqli_fetch_array($crumb_query, MYSQLI_ASSOC); $crumbs = array("index.php" => "Board Index", "./view_category.php?cid={$crumb_info['cat_id']}" => $crumb_info['cat_name'], "./view_topics.php?fid=$forum_id" => $crumb_info['forum_name']); echo build_crumbs($crumbs); the function: function build_crumbs($crumbs) { foreach($crumbs as $key => $value) { $crumb_display = "<a href=\"{$key}\">{$value}</a>"; $crumb_display = implode(" - ", $crumbs); } return $crumb_display; } can anyone see where im going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/222492-foreach-loop/ Share on other sites More sharing options...
doddsey_65 Posted December 23, 2010 Author Share Posted December 23, 2010 when i remove the implode function it works fine and they are links. whats wrong with the implode function then? Quote Link to comment https://forums.phpfreaks.com/topic/222492-foreach-loop/#findComment-1150736 Share on other sites More sharing options...
johnny86 Posted December 23, 2010 Share Posted December 23, 2010 This is your $crumbs array: Array ( [index.php] => Board Index [./view_category.php?cid=] => [./view_topics.php?fid=] => ) Is that really what you want? You should atleast give those indexes a value. So it will get printed out in build_crumbs. And also you have to change your build function: function build_crumbs($crumbs) { $crumb_display = ""; foreach($crumbs as $key => $value) { $crumb_display .= "<a href=\"{$key}\">{$value}</a>"; $crumb_display .= implode(" - ", $crumbs); } return $crumb_display; } Quote Link to comment https://forums.phpfreaks.com/topic/222492-foreach-loop/#findComment-1150737 Share on other sites More sharing options...
doddsey_65 Posted December 23, 2010 Author Share Posted December 23, 2010 no my $crumbs array is array( "index.php" => "Board Index", "./view_category.php?cid={$crumb_info['cat_id']}" => $crumb_info['cat_name'], "./view_topics.php?fid=$forum_id" => $crumb_info['forum_name']); the values are taken from the database as are part of the keys. also adding the implode like that to the variable using the .= operator just repeats the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/222492-foreach-loop/#findComment-1150738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.