As "doinitanistor" pointed out, this contribution is not really complete, as it still sometimes displays inactive categories, or lists products of inactive categories. To overcome this, it was enough to add status_categ = 1 or c.status_categ = 1 in relevant queries in some additional files.
But I couldn't find a solution for the file products_new.php. Probably my question is just a MySQL syntax question...
The original query is:
$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
I cannot just add the status_categ = 1, since the table TABLE_CATEGORIES is not mentioned. If I add it in the query like below, every article will be listed multiple times (14 times to be exact, the total number of my categories):
$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name, c.status_categ from " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where c.status_categ = 1 AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
So I thought to include the table TABLE_PRODUCTS_TO_CATEGORIES as well, and next to make additional 'where' clausules, it would fix that problem:
$products_new_query_raw = "select p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_PRODUCTS_DESCRIPTION . " pd where c.status_categ = 1 AND c.categories_id = p2c.categories_id AND p.products_id = p2c.products_id AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
But now I get a result of 406 products, instead of the 393, which it should be. I suspect this is (partly) due to 'cloned' entries. So I tried to add a "distinct" in the query:
$products_new_query_raw = "select distinct p.products_id, pd.products_name, p.products_image, p.products_price, p.products_tax_class_id, p.products_date_added, m.manufacturers_name from " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on (p.manufacturers_id = m.manufacturers_id), " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_DESCRIPTION . " pd where c.status_categ = 1 AND c.categories_id = p2c.categories_id AND AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added DESC, pd.products_name";
and also add "products_id" in the following line to get to:
$products_new_split = new splitPageResults($products_new_query_raw, MAX_DISPLAY_PRODUCTS_NEW, 'p.products_id');
But this will still generate an error:
Quote
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_i' at line 1
select count(distinct p.products_id) as total from products p left join manufacturers m on (p.manufacturers_id = m.manufacturers_id), categories c, products_description pd where c.status_categ = 1 AND c.categories_id = p2c.categories_id AND AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1'
select count(distinct p.products_id) as total from products p left join manufacturers m on (p.manufacturers_id = m.manufacturers_id), categories c, products_description pd where c.status_categ = 1 AND c.categories_id = p2c.categories_id AND AND p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '1'










