Hi Matthias,
No I don't think its the same (although I could be wrong).
The way your solution works I think you would have to know the category id for the category you want to display ie $categoryid[n] - which you would in some cases and as you say would then have significantly fewer database calls.
The way I set up for my solution was to find out the category which is n steps deep in the category path - and so may have a different $categoryid each time
e.g. a simplified extract of my course_catetories table might look something like this
categoryid |
category name |
category path |
1 |
Faculty of Education |
|
2 |
Faculty of Arts |
|
3 |
Secondary ITT |
/1 |
4 |
Secondary Science |
/1/3 |
5 |
Primary ITT |
/1 |
6 |
Curriculum 7-11 |
/1/5 |
My understanding is that with your solution, I could set $categoryid[1] to always display 'Faculty of Education' or $category[2] to always display 'Faculty of Arts' and so on - whatever the actual pattern of categories/sub categories. And this may be exactly what is wanted in some circumstances - in which case, as you say, your code would be the better one to use as it minimises database calls.
My solution - which was done purely for my learning and not for my practical application, although I believe Miriam has found it worked for her - is to be able to display the nth step in the category path. For instance if I have 2 courses - 'Practical lab work' in the Secondary Science category and Teaching IT in the Curriculum 7-11 category, the breadcrumbs for these would look like:
My Home>Faculty of Education>Secondary ITT>Secondary Science>Practical Lab Work
My Home>Faculty of Education>Primary IT>Curriculum 7-11>Teaching IT
If, in my code, the $depth is set to 2 then the $category name (possibly as part of the header being displayed) would, in the first example, display 'Secondary ITT' and would do so for any other courses, however many sub-categories deep within the Secondary ITT department (My Home would be $depth=0 etc), while in the second example it would display 'Primary IT' for this course and any others in the Primary ITT category and further sub-categories.
So the reason for the extra database calls is to determine and then breakdown the path of categories for the course - stored as a single string in the table as above - and then to find the name of the nth category in that path, which could have a different $categoryid for different courses.
That at least is my understanding of the differences between the two solutions
HTH
Richard