Hi everybody,
I need any help I can get, anyone?1?! Please I am desperate!
Here is my code:
function get_categories($moduleId=0)
{
$this->moduleId = $moduleId; $query = 'SELECT
categoryId,
categoryParentId,
translations.*
FROM
categories,
translations
WHERE
categories.translationId=translations.translationId
AND
categories.categoryModuleId=\'6\'
AND
categories.categoryStatus=\'1\'
AND
translations.translationLanguage=\'pt-br\'
GROUP BY
categories.categoryId
ORDER BY
categories.categoryOrder';$this->framework->database->query($query);
if($this->framework->database->num_rows() > 0)
{
while ($this->framework->database->fetch_array())
{
$this->categories[] = $this->framework->database->row;
}
}
} function get_category($categoryId='')
{
if($categoryId != '')
{
$t = count($this->categories);
$i=0;
while ($i<$t)
{
if($this->categories[$i]['categoryId'] == $categoryId)
{
foreach($this->categories[$i] as $var=>$val)
{
$category[$var] = $val;
}
$i = $t;
}
else
{
$i++;
}
}
return $category;
}
} function get_parent_categories($parentId='')
{
if($parentId != '')
{
$t = count($this->categories);
$i=0;
$c=0;
while ($i<$t)
{
if($this->categories[$i]['categoryParentId'] ==
$parentId)
{
foreach($this->categories[$i] as $var=>$val)
{
$categories[$c][$var] = $val;
}
}
$c++;
$i++;
}
return $categories;
}}
function get_categories_tree($categoriesId='')
{
if($categoriesId != '' && is_array($categoriesId))
{
$t = count($categoriesId);
$c = $t;
for($i = $t; $i >= 1; $i--)
{
if(!eregi('.html',$categoriesId[$i]) && !eregi('.htm',$categoriesId[$i]) && eregi('[0-9]',$categoriesId[$i]))
{
$category[$c] = $this->get_category($categoriesId[$i]);
if($category[$c]['categoryParentId'] != '0')
{
$category[$c]['categoryParents'] = $this->get_parent_categories($category[$c]['categoryParentId']);
$t2 = count($category[$c]['categoryParents']);
for($i2=$t2;$i2>=1;$i2--)
{
}
}
else
{
$c--;
$category[$c] = $this->get_different_categories($category[$c]['categoryParentId']);
}
$c--;
}
}
}
print_r($category);
}
It outputs:
Array
(
[6] => Array
(
[categoryId] => 3
[categoryParentId] => 2
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
[categoryParents] => Array
(
[2] => Array
(
[categoryId] => 3
[categoryParentId] => 2
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
))
)
[5] => Array
(
[categoryId] => 2
[categoryParentId] => 1
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
[categoryParents] => Array
(
[1] => Array
(
[categoryId] => 2
[categoryParentId] => 1
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
))
)
[4] => Array
(
[categoryId] => 1
[categoryParentId] => 0
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
) [3] => Array
(
[categoryId] => 1
[categoryParentId] => 0
[translationId] => 123456789
[translationLanguage] => pt-br
[field01] => Casa
[field02] =>
[field03] =>
[field04] =>
[field05] =>
[field06] =>
[field07] =>
[field08] =>
[field09] =>
[field10] =>
))
Many thanks, Bruno B B Magalhaes
On Oct 20, 2004, at 12:30 PM, Bobo Wieland wrote:
this is some code i've written once that gets all supercategories from a mysql db... Take it as it is... It prints out a html-string of links like this:
Category : sub_cat1 : sub_cat2 : sub_cat3.
Maybe you can figure it out... it takes the current id (in your example catId13) as a parameter and goes up to the root...
function catPathRec($id, $show_lnk = false, $rtn_val="") {
global $link_id;
$katname = strtoupper(mysql_result(mysql_query("SELECT kat_namn AS kat FROM text_kat WHERE id = ".$id, $link_id), "kat"));
$hid = mysql_result(mysql_query("SELECT h_id AS hkat FROM text_kat WHERE id = ".$id, $link_id), "hkat");
if ($rtn_val == "") {
if ($show_lnk) { return ($hid == 0) ? ("<a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>") : (catPathRec($hid, $show_lnk, " : <a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>")); }
else { return ($hid == 0) ? ($katname) : (catPathRec($hid, $show_lnk, " : ".$katname)); }
}
else if ($hid != 0) { return catPathRec($hid, $show_lnk, " : <a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>".$rtn_val); }
return "<a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>".$rtn_val."\n";
}
----- Original Message ----- From: "Bruno B B Magalhães" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "php-db" <[EMAIL PROTECTED]>
Sent: Wednesday, October 20, 2004 4:47 AM
Subject: [PHP-DB] Reverse (or backward?) Infinity Loop
Hi guys,
I have a normal categories table:
catId catParentId catName catStatus
But I want when a user enters on:
http://hostname/site/products/catId1/catId7/catId13/../../ contentId.html
A listing should apear like that:
• Category 1 • Category 7 • Category 13 • Category 2 • Category 3 • Category 4 • Category 5
A reverse (or backward) loop! We need to get the last category and then follow the ParentId until the 0 ParentId. Have anybody made this before (I hope so)?
Many Thanks, Bruno B B Magalhaes
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
