Advertisement
FranklinC

PHP Breadcrumbs Function

Jun 30th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. function  breadcrumb($id, $cat, $ext = null) {
  2.  $s = "SELECT * FROM category WHERE (id = $id)";
  3.  $r = mysql_query($s);
  4.  $row = mysql_fetch_array($r);
  5.  if($row['parent_id'] == 0) {
  6.   $id = $row['id'];
  7.   $name = $row['name'];
  8.   if(!empty($except)  &&  $ext == $row['id']) {
  9.    return  "Home";
  10.    
  11.   }
  12.   return  "Home » ".$name."";
  13.  }
  14.  else {
  15.   if(!empty($ext)  &&  $ext == $row['id']) {
  16.    $id = $row['id'];
  17.    $name = $row['name'];
  18.    return  breadcrumb($row['parent_id'],$cat_tbl, false). " $name";
  19.    
  20.   }
  21.    $name = $row['name'];
  22.   return  breadcrumb($row['parent_id'],$cat_tbl, false). "» ".$name."";
  23.  }
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. =======================
  32. Here is a simple function for breadcrumbs.
  33.  
  34.  
  35. In this example the database would have id, parent_id, and name. So an example table with data would look like the following:
  36.  
  37.  
  38. 1 0 root1
  39. 2 0 root2
  40. 3 1 subforroot1
  41. 4 3 subforid3
  42.  
  43.  
  44. The parent_id as 0 is the root location. Anything else is a sub folder of some sort.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement