You are here: Re: I have sub-categories but want to display full category path « PHP Programming Language « IT news, forums, messages
Re: I have sub-categories but want to display full category path

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация