Salvo Posted December 6, 2005 Posted December 6, 2005 Hi all with the script below I like to retrieve all categories that have a special offers only but I have ONE problem if category A has 5 special offers, the category A will show 5 times in the drop down. Can someone see what I don't see and what I should add to show only 1 category only even if 5 special are in that category? Thanks // Display the list of the cuisines function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false) { global $languages_id; if (!is_array($category_tree_array)) $category_tree_array = array(); if ( (sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => TEXT_ALL_CUISINES); if ($include_itself) { $category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.categories_id = '" . (int)$parent_id . "'"); $category = tep_db_fetch_array($category_query); $category_tree_array[] = array('id' => $parent_id, 'text' => $category['categories_name']); } $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = p2c.products_id and p.products_id = s.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.categories_name"); while ($categories = tep_db_fetch_array($categories_query)) { if ($exclude != $categories['categories_id']) $category_tree_array[] = array('id' => $categories['categories_id'], 'text' => $spacing . $categories['categories_name']); $category_tree_array = tep_get_category_tree($categories['categories_id'], $spacing . '???', $exclude, $category_tree_array); } return $category_tree_array; }
gscreations Posted December 6, 2005 Posted December 6, 2005 Hi all with the script below I like to retrieve all categories that have a special offers only but I have ONE problem if category A has 5 special offers, the category A will show 5 times in the drop down. Can someone see what I don't see and what I should add to show only 1 category only even if 5 special are in that category? Thanks // Display the list of the cuisines function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false) { global $languages_id; if (!is_array($category_tree_array)) $category_tree_array = array(); if ( (sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => TEXT_ALL_CUISINES); if ($include_itself) { $category_query = tep_db_query("select cd.categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.categories_id = '" . (int)$parent_id . "'"); $category = tep_db_fetch_array($category_query); $category_tree_array[] = array('id' => $parent_id, 'text' => $category['categories_name']); } $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = p2c.products_id and p.products_id = s.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.categories_name"); while ($categories = tep_db_fetch_array($categories_query)) { if ($exclude != $categories['categories_id']) $category_tree_array[] = array('id' => $categories['categories_id'], 'text' => $spacing . $categories['categories_name']); $category_tree_array = tep_get_category_tree($categories['categories_id'], $spacing . '???', $exclude, $category_tree_array); } return $category_tree_array; } not sure if you've tried it might work put LIMIT 1 on end of your $categories_query ?
boxtel Posted December 6, 2005 Posted December 6, 2005 not sure if you've tried it might work put LIMIT 1 on end of your $categories_query ? select distinct ? Treasurer MFC
gscreations Posted December 6, 2005 Posted December 6, 2005 select distinct ? yes that should do it too :thumbsup:
Salvo Posted December 6, 2005 Author Posted December 6, 2005 Thanks to all. distinct has worked. This would make be a nice contribution. I am not an expert, so if you like to help in expanding it and post it for all I would like your help in it. Thanks
Recommended Posts
Archived
This topic is now archived and is closed to further replies.