Forum Moderators: coopster
I would like to dynamically create a breadcrumb trail by pulling data from a database. I would like to display both parent categories and sub-categories. Very similar to the one that this site uses (see above).
I already have the table. It contains (CatID, CatName, CatParent).
Has anybody created one of these, or could they point me in the right direction, i.e., online tutorials using MySQL & PHP.
Cheers in advance. :)
in most of the tutorial i have come across, they use a different methodology
you can find a good ones here:
[evolt.org...]
[zend.com...]
hope this helps
:)
[edited by: jatar_k at 4:26 pm (utc) on July 11, 2005]
Thanks for the help thus far.
What I am trying to do is this:
function Breadcrumbs($_Get[CatID]) {
$result = mysql_query("SELECT CatID, CatName, CatParent FROM categories WHERE CatName='$_GET[CatID]';");
$row = mysql_fetch_array($result);
I am not sure if my syntax is correct.?.?
I am trying to call the above from this link on the index page:
<a href="http://localhost/site/test.php?CatID=1">Test</a>;
Once again, thank for your help. It is really appreciated.
I am pretty sure it has something to do with the array position.
This is the code I am using:
function Breadcrumbs($CatParent = 0)
{
$query = "SELECT CatID, CatParent, CatName FROM categories";
$result = mysql_query($query) or die('<p>Error: ' . mysql_error().'.</p>');
list($CatID, $CatParent, $CatName) = @mysql_fetch_row($result);
if($CatParent > 0)
{
Breadcrumbs($CatParent);
}
else
{
echo "<p><a href=\"index.php\">Home</a> > $CatName</p>";
}
}
return Breadcrumbs(0);
I am not sure if it is correct. I pinched it from some site and altered it to such my requirements.
Cheers for you help!
coz u got this here
else
{
echo "<p><a href=\"index.php\">Home</a> > $CatName</p>";
}
try
return Breadcrumbs($CatParent);
===================================
this is the function id use, based on slight modification of ur earlier sql. im not sure this will work as havent tested it, if it doesnt then theres something wrong with the syntax and not the logic.
function Breadcrumbs($CatID)
{
$sql = mysql_query("SELECT CatID, CatName, CatParent FROM categories WHERE CatID='$CatID'"); //assuming CatID is primary and you have declared $CatID=$_GET['CatID']
$num = mysql_num_rows($sql);
$result = mysql_fetch_assoc($sql);
if(!($num=1) ¦¦!$CatID ¦¦ $sql)
{
$nav .= "Home"; //theres error so not showing breadcrumb
}
else
{
$nav .= "<a href=\"index.php\">Home</a> > ".$result["CatName"];
}
return $nav;
}
lets see if that works for u :)