fastof,
$tree = array();
$dirid = $cat;
while ($dirid != '0' && $dirid != "") {
$req = mysql_query("SELECT * FROM `download` WHERE `type` = 'cat' and `id` = '153' LIMIT 1");
$res = mysql_fetch_array($req);
$tree[] = '<a href="index.php?cat=153">' . $res['text'] . '</a>';
$dirid = $res['refid'];
}