function getCatTree($fold_id) { $query = "SELECT name, pid FROM cat WHERE id = {$fold_id};"; $result = mysql_query($query); $row = mysql_fetch_array($result); if ($row[1] != 0) { $tree = getCatTree($row[1]) . $row[0] . "/"; } elseif ($row[0] != false) { $tree = "/" . $row[0] . "/"; } else { $tree = "/"; } return $tree; }
/** *This function generates an absolute URL for given article or category. *Only $article_id OR $cat_id should be provided! *This method functions as a wrapper for getCatTree. * *@param int $article_id *@param int $cat_id *@param resource current valid link to database *@return string absolute URL for provided article or category * */ public function generateURL($article_id, $cat_id, $link_identifier) { if (isset($article_id)) { $query = "SELECT cat_id, title FROM article WHERE id = {$article_id};"; $result = mysql_query($query, $link_identifier); $row = mysql_fetch_array($result); $cat_id = $row[0]; $tree = self::getCatTree($cat_id, $link_identifier); $URL = $tree . $row[1] . ".html"; return $URL; } elseif (isset($cat_id)) { $URL = getCatTree($cat_id, $link_indentifier); return $URL; } else { return false; } }