Search the Community
Showing results for tags 'bread crumbs php'.
-
0down votefavorite I just converted a query that displays "bread crumbs" style navigation links to PDO: function get_path($dbh,$node,$TopnavTable, $TopnavName) { $stmt = $dbh->prepare("SELECT name FROM $TopnavTable WHERE $TopnavName = ?"); $stmt->bindValue(1,$node); $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_ASSOC); $row = $stmt->fetch(); $path = array_merge(get_path($pdo,$row['Parent'], $TopnavTable, $TopnavName), $path); return $path ; } I also figured out a way to display the results: $Path2 = explode("/", $path); $Path2[1] = '<a href="/Topics">'.$Path2[1].'</a>'; $Path2[2] = '<a href="/Topics/'.$Path2[2].'">'.$Path2[2].'</a>'; $Path2[3] = '<span class="navHere"><b>'.$Path2[3].'</b></span>'; echo join( $Path2, ' > ' ); However, it only works only if I'm working with an array consisting of three segments. For example, I'm viewing the URL MySite/Topics/Washington/Governor, which displays the following bread crumbs trail: Topics > Washington > Governor If I view MySite/Washington, it should display... Topics > Washington But I get an error message: Undefined offset: 3, plus there's a trailing arrow (>) after Washington. So I'm trying to figure out how to make this work with any number of segments - 2, 3, 6, etc. Regardless of the number of segments, I'd like the last segment to be unlinked. (I'm going to further put it inside a span.) Does anyone have any tips? (If there's a completely different way of doing it that's better, I'd love to hear about it.)