|
Posted by Michael Fesser on 02/05/07 14:41
..oO(Phil Latio)
>Based on your model I came up with the following. It uses Jason Gilmore's
>MySQL connection class from his book "Beginning PHP5 and MySQL" published by
>Apress.
You don't have to reconnect to the MySQL server in each and every loop.
Do it once before entering the while loop, then just fire your queries.
>I am quite pleased with this as I managed to get rid of the trailing >>
>which looked very untidy.
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));
}
Micha
Navigation:
[Reply to this message]
|