@dnmknin verdiği kodda ise biraz değişiklik lazım, yani şu şekilde istediğini yapar;
// $node is the name of the node we want the path of
function get_path($node) {
// look up the parent of this node
$result = mysql_query("SELECT * FROM kat WHERE kat_id = '$node'");
$row = mysql_fetch_array($result);
// save the path in this array
$path = array();
// only continue if this $node isn't the root node
// (that's the node with no parent)
if ($row['ustkat_id'] != 0) {
// the last part of the path to $node, is the name
// of the parent of $node
$path[] = $row['kat_adi'];
// we should add the path to the parent of this node
// to the path
$path = array_merge(get_path($row['ustkat_id']), $path);
}
// return the path
return $path;
}kategori listesini array içine alır. örneğin kat_sef değeri olarak fsef gönderip o kategorinin üst kategorilerin array çıktısının içeriğini şu kodla görmek istediğimde
$katlist = get_path('fsef');
print_r($katlist);çıktısı aşağıdaki gibi olur;
Array
(
[0] => aaa
[1] => bbb
[2] => ddd
[3] => fff
)bu array'i foreach ile istediğin şekilde çıkarıp biçimlendirip kullanabilirsin.
ayrıca
sdemirkeser in verdiği linkteki sql sorgusuda işini görür kolay gelsin.