Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

modify query to display categories


Retro

Recommended Posts

I need to set up two boxes displaying different categories, so I'm trying to modify the categories query in categories.php to display only certains categories and do this on the new box.

 

I have found the query but I'm not able to restrict it to only certain categories id such 1, 3, 7...

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

 

 

thank you!

Link to comment
Share on other sites

If I understand this correctly, you only want category, say #1 and its subcategories, then use

 

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '1' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by sort_order, cd.categories_name");

Link to comment
Share on other sites

The following will work. You have to fill the categories_array() however ..

 

$categories_array = ("'1','3', '7'");
$categories_query = tep_db_query("
SELECT c.categories_id, cd.categories_name, c.parent_id
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.categories_id IN($categories_array)
AND c.categories_id = cd.categories_id
AND cd.language_id='" . (int)$languages_id ."'
order by c.parent_id, sort_order, cd.categories_name");

Link to comment
Share on other sites

thank you! it's working fine!

 

but... when I try to do the same on a second categories box it doesn't display anything :(

I tested the two ways, filtering per parent category or using an array

 

I renamed the function tep_show_category but it doesn't work

Link to comment
Share on other sites

thank you! it's working fine!

 

but... when I try to do the same on a second categories box it doesn't display anything :(

I tested the two ways, filtering per parent category or using an array

 

I renamed the function tep_show_category but it doesn't work

 

As long as it is fed the correct categories_ids that SQL will output them.

 

tep_show_category is an existing function in includes/boxes/categories.php .. choose a more individual/obscure function name

 

function tep_my_unique_categories() or something

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...