A MySQL query, using self-joins to establish parent-child relations names the results as [FONT=Courier New]up3_name[/FONT], [FONT=Courier New]up2_name[/FONT], [FONT=Courier New]up1_name[/FONT] and [FONT=Courier New]this_name[/FONT]. The number of levels can be 1, 2, 3 or 4. Using [FONT=Courier New]CONCAT_WS()[/FONT] these are assembled as [FONT=Courier New]'modpath'[/FONT]:
/up3_name/up2_name/up1_name/this_name/ or /up2_name/up1_name/this_name/, etc. down to simply this_name/
While the query is filtered on [FONT=Courier New]'this_name'[/FONT] Apache's [FONT=Courier New]mod_rewrite[/FONT] is used to map displayed url of
mysite.com/up3_name/up2_name/up1_name/this_name/
to the php script index.php?name=this_name
So for every row, [FONT=Courier New]'this_name'[/FONT] has a [FONT=Courier New]'modpath'[/FONT] value, and all hrefs within the page use that [FONT=Courier New]'modpath'[/FONT] value.
In order to use the [FONT=Courier New]'modpath'[/FONT] value as breadcrumbs, i need to split [FONT=Courier New]'modpath'[/FONT] into as many substrings as necessary (1-4). Then, I believe I need to build the correct href for each breadcrumb level and reassemble them all into usable breadcrumbs. So:
1. explode the 'modpath' value:
/up3_name/up2_name/up1_name/this_name/
into
up3_name
up2_name
up1_name
this_name
2. assemble the appropriate href for each:
up3_name (href=/up3_name/)
up2_name (href=/up3_name/up2_name/)
up1_name (href=/up3_name/up2_name/up1_name/)
this_name (href=/up3_name/up2_name/up1_name/this_name/)
3. implode and echo the name with appropriate href with a separator as breadcrumbs:
up3_name > up2_name > up1_name > this_name
I have chunks of this working, but there are two related problems that keep popping up:
Extraneous separators and extraneous hrefs when there are less than four levels.
It seems like I somehow need to form the individual chunks, then implode them based on how many substrings exist for each level, but my php skills are still rudimentray and I'm having trouble getting it all to come together.
Below is the php for my current building-block page. Below that are 4 live links pulling from a database (each showing a level from 1-4) to make it easier to see the results. I really appreciate any help in thinking this through. Thanks!
Current working Dreamweaver code elements (note: I'm not planning on using all of these, but it's helpful for me to try different techniques to see the results, then go back and only use what works. Also note that this page is not currently mod_rewrite):
<?php
$path = explode ("/", $row_rsThis['modpath']);
// Make the HREFs [1] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$path3 = $path[0] . "/";
$path2 = $path[0] . "/" . $path[1] . "/";
$path1 = $path[0] . "/" . $path[1] . "/" . $path[2] . "/";
$path0 = $path[0] . "/" . $path[1] . "/" . $path[2] . "/" . $path[3] . "/";
echo "<p><strong>echo the paths for reference only:</strong></p>";
echo "<p>" . $path3 . "</p>";
echo "<p>" . $path2 . "</p>";
echo "<p>" . $path1 . "</p>";
echo "<p>" . $path0 . "</p>";
// Make the Breacrumb Names ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "<hr size='1' noshade='noshade' /><p><strong>echo the names as breadcrumbs for reference only:</strong></p>";
$name3 = str_replace ("-", " ", $path[0]);
$name2 = str_replace ("-", " ", $path[1]);
$name1 = str_replace ("-", " ", $path[2]);
$name0 = str_replace ("-", " ", $path[3]);
echo "<p>" . $name3, ' > ', $name2, ' > ', $name1, ' > ', $name0;
?>
</p><hr size="1" noshade="noshade" />
<p><strong>assemble the breadcrumbs from rsThis</strong> (upname3, etc)</p>
<p>
<?php echo $row_rsThis['up3_name']; ?> :::
<?php echo $row_rsThis['up2_name']; ?> :::
<?php echo $row_rsThis['up1_name']; ?> :::
<strong><?php echo $row_rsThis['this_name']; ?>
</strong></p><hr size="1" noshade="noshade" />
<p><strong>add the hrefs from $path</strong> (upname3, etc)</p>
<p>
<a href="<?php echo $path3; ?>"><?php echo $row_rsThis['up3_name']; ?></a> :::
<a href="<?php echo $path2; ?>"><?php echo $row_rsThis['up2_name']; ?></a> :::
<a href="<?php echo $path1; ?>"><?php echo $row_rsThis['up1_name']; ?></a> :::
<strong><?php echo $row_rsThis['this_name']; ?></strong></p>
<hr size="1" noshade="noshade" />
<!-- NEW TRY ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<h4>new try</h4>
<?php
$path = explode ("/", $row_rsThis['modpath']);
// Get the individual chunks ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
$path3 = $path[0]; // up3
$path2 = $path[1]; // up2
$path1 = $path[2]; // up1
$path0 = $path[3]; // this
echo "<hr size='1' noshade='noshade' /><p><strong>individual substrings for this page:</strong></p>";
echo "<p>" . $path3 . "</p>";
echo "<p>" . $path2 . "</p>";
echo "<p>" . $path1 . "</p>";
echo "<p>" . $path0 . "</p>";
// make an href for each level :::::::::::::::::::::::::::::::::::::::
echo "<hr size='1' noshade='noshade' /><p><strong>make an individual href for each level:</strong></p>";
$mod3 = $path3 . "/";
$mod2 = $path3 . "/" . $path2 . "/";
$mod1 = $path3 . "/" . $path2 . "/" . $path1 . "/";
$mod0 = $path3 . "/" . $path2 . "/" . $path1 . "/" . $path0 . "/";
echo "<p>" . $mod3 . "</p>";
echo "<p>" . $mod2 . "</p>";
echo "<p>" . $mod1 . "</p>";
echo "<p>" . $mod0 . "</p>";
// path for this page ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "<hr size='1' noshade='noshade' /><p><strong>echo path for this page only:</strong></p>";
$put = implode ('/', $path);
echo "<p>" . $put . "</p>"; // writes modpath for this page
// breadcrumbs ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo "<hr size='1' noshade='noshade' /><p><strong>echo breadcrumbs for this page only:</strong></p>";
$crumbs = implode (' > ', $path);
echo "<p>" . $crumbs . "</p>"; // writes modpath for this page
?>
<hr size="1" noshade="noshade" />
<p><strong>make the breadcrumbs with hrefs:
</strong></p>
<p>
<a href="<?php echo $mod3; ?>"><?php echo $path3; ?></a>
<a href="<?php echo $mod2; ?>"><?php echo $path2; ?></a>
<a href="<?php echo $mod1; ?>"><?php echo $path1; ?></a>
<a href="<?php echo $mod0; ?>"><?php echo $path0; ?></a></p>
Links:
1 breacrumb level: http://bigpath.net/water1/strings4.php?name=Recreation-and-Land
2 breacrumbs levels: http://bigpath.net/water1/strings4.php?name=Recreation-Program
3 breacrumbs levels: http://bigpath.net/water1/strings4.php?name=Recreation-Areas
4 breacrumbs levels: http://bigpath.net/water1/strings4.php?name=Lake-Owl