Forum Moderators: coopster

Message Too Old, No Replies

Simple breadcrumbs script

         

field4000

6:40 am on Jul 11, 2005 (gmt 0)

10+ Year Member



Hey all,

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. :)

maxi million

9:15 am on Jul 11, 2005 (gmt 0)

10+ Year Member



i have created one actually...but it probably wont be any good to you because my breadcrumb is not based on the dir structure but the URL. since i m passing a lot of data thru get method and it typically looks like this: www.examplesite.com/?page=pageone&action=dothis&cat=1
it works great for me

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]

henry0

11:52 am on Jul 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should check our "Bag o' tricks"
here's one

From bag 3
[webmasterworld.com]

field4000

5:29 am on Jul 12, 2005 (gmt 0)

10+ Year Member



Hey,

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.

maxi million

8:35 am on Jul 12, 2005 (gmt 0)

10+ Year Member



the way you want to do it seems to be pretty much close to what i have done also. dont think it should give you any problems. it should do the trick. are you getting any errors?

field4000

2:19 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



I am not getting errors, just the wrong output. I keep getting the same output regardless of what link is clicked (using the above code).

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!

maxi million

4:14 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



sorry pal, i dunno how far can i be helpful, but i feel the problem is with this line:
return Breadcrumbs(0)

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 :)