soulbro Posted January 8, 2009 Share Posted January 8, 2009 Hi all, I hope someone can help as im stuck on a problem past 2 days now.. Using the tutorial on this site http://www.sitepoint.com/print/hierarchical-data-database/, I created a new column called 'parent' for each page in my site, and each page now has a 'parent'. Using a recursive function, I access the database and create a two-dimensional array to find the path back to the root node of any particular page like so: function get_path($parent_column) { $sql = "select id, display_name, page_name, parent from page_admin where id ='$parent_column'"; $rs = mssql_query($sql);// or die(echo("Error on page retrieve_contents.php on line 125")); $row = mssql_fetch_array($rs); $path = array(); if ($row['parent']!='') { //creating a 2 dimensional array $path[] = array($row['parent'], $row['display_name'], $row['page_name'], $row['id']); //$path = array($row['parent'],$row['display_name'],$row['page_name'],$row['id']; $path = array_merge(get_path($row['parent']), $path); } return $path; } Now I am stuck on how to extract the information needed from the array to create a breadcrumb trail. I want to create a kind of trail with links like : - Home -> About Us -> More Info etc etc The array $path looks like Array ( [0] => Array ( [0] => 0 [1] => Home [2] => index [3] => 1 ) [1] => Array ( [0] => 1 [1] => About us [2] => aboutus [3] => 2 ) ) But I can't understand how to pick out the individual items to create the breadcrumb trail. If anyone can help, would be really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/139979-solved-2d-array-need-help-to-get-values/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 Well I do not see the "more info" but... $returned = get_path($parent); foreach ($returned as $path) { $bc[] = $path[1]; } $bc = implide(" -> ", $bc); echo $bc; Will at least do the home and about us. Quote Link to comment https://forums.phpfreaks.com/topic/139979-solved-2d-array-need-help-to-get-values/#findComment-732362 Share on other sites More sharing options...
soulbro Posted January 8, 2009 Author Share Posted January 8, 2009 Sorry I gave the "more info" path as an example, although the code I supplied was for the About Us page, however your code works automatically for any page (you genius!!) Thank you premiso. I edited slightly so it uses the 3rd column of the array to create links on the names like so: foreach ($array as $path) { $bc[] = "<a href=".$path[2].".php>".$path[1]."</a>"; } $bc = implode(" -> ", $bc); echo $bc; Quote Link to comment https://forums.phpfreaks.com/topic/139979-solved-2d-array-need-help-to-get-values/#findComment-732383 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.