| 
	
 | 
 Posted by Phil Latio on 02/05/07 15:04 
> There's another (IMHO easier) way to avoid that: While running the 
> queries collect all breadcrumb items in an array. After that reverse the 
> array and just use implode() to print it out with '>>' separators. Also 
> set error_reporting to E_ALL while developing - your code will throw 
> some notices. 
> 
> Slightly modified, but untested: 
> 
> function breadcrumb($object) { 
>  $db = new MySQL("*****", "*****", "*****", "***"); 
>  $db->connect(); 
>  $db->select(); 
>  $breadcrumb_array = array(); 
>  while ($object > 0) { 
>    $db->query(" 
>      SELECT category_name, parent_category_id 
>      FROM category 
>      WHERE category_id = $object" 
>    ); 
>    $result = $db->fetchArray(); 
>    $breadcrumb_array[] = $result['category_name']; 
>    $object = $result['parent_category_id']; 
>  } 
>  print implode(' >> ', array_reverse($breadcrumb_array)); 
> } 
 
Thanks for this extra feedback. Always good to see other peoples ideas. 
 
Not come across "array_reverse" before although "implode" sounds familiar  
but not used that either. I will check them out. 
 
Cheers 
 
Phil
 
  
Navigation:
[Reply to this message] 
 |