Supertex Posted June 3, 2015 Share Posted June 3, 2015 I've noticed that when I put a space in the search box and hit enter, while on categories.php, it returns a list of ALL categories and products in my store, which I find very useful. However, in cases where I have linked a product to another category, I get duplicate entries. I would like to limit the number of times a product ID will be returned to 1. I've seen DISTINCT used in queries, but I'm not sure how to structure the query so that only products_id is affected. For instance, it would be a short list if DISTINCT affected product status in addition to products_id. Also, I'm not sure how it might affect categories, since they don't have a product id... Haven't found anything that looks like it applies to this on Stack Overflow, but perhaps I can't see the forest for the trees? Mind steering me in the right direction? osC v2.3.1 MySQL v8.0.32 PHP v5.6.40 Installed addons: . Attribute Sets Plus .. Create Account & Manual Order Maker .. Customer Testimonials 2.3.4 .. Customer Blacklist .. Dynamic Info Pages .. FedEx Web Svcs v9 .. Filtered Sales Report .. Generic Box .. Google XML Sitemap SEO .. Maximum Order Value .. Modular Front Page .. Monthly Sales & Tax Report .. Multiple Products Manager .. Must Accept Terms & Conditions .. Order Editior .. PDF Customer Invoice .. Price in Cart Only .. Product Sort/Order .. Product Sort in Cart .. Quantity Discounts .. Restrict Delivery Methods .. SEO Header Tags - Reloaded .. Separate Pricing Per Customer .. Simpler Admin Session Length Control .. Sitemap SEO .. Show Free Ship + Modules .. Specials by Category for SPPC .. Store Mode (open|closed|maintenance) .. Store Pickup Shipping .. Theme Switcher .. Ultimate SEO URLs 5 Pro .. UPS XML Rates & Svcs 1.4 .. USPS methods 7.3.1 .. Who's Online Dashboard . Fixes: Add to cart -> 'product not found' : FIX Login issues with IE 11 : FIX Tools: Incredibly Handy: osC Xref Link to comment Share on other sites More sharing options...
AjitKhodke Posted June 19, 2015 Share Posted June 19, 2015 Can you detailed your table structure? SAP Hosting On Cloud by ESDS Link to comment Share on other sites More sharing options...
♥bruyndoncx Posted June 19, 2015 Share Posted June 19, 2015 distinct only returns unique records, so as long as you do not reference categories data or product_to_categories in the selection of fields you won't get duplicates but it is returning categories data in order to populate the cPath to create the edit link I think KEEP CALM AND CARRY ON I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support). So if you are still here ? What are you waiting for ?! Find the most frequent unique errors to fix: grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt Link to comment Share on other sites More sharing options...
Supertex Posted June 19, 2015 Author Share Posted June 19, 2015 I've come to realize this is less trivial than I first thought. Perhaps I should leave well enough alone. Nonetheless, here is my search query: if (isset($HTTP_GET_VARS['search'])) { $products_query = tep_db_query("select p.products_model, p.products_weight, p.price_in_cart, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.products_sort_order, pg.customers_group_price, s.specials_new_products_price, s.customers_group_id, pi.image, pi.sort_order, p2c.categories_id, pd.products_url, pas2p.products_attributes_sets_id from " . TABLE_PRODUCTS . " p join " . TABLE_PRODUCTS_DESCRIPTION . " pd on (p.products_id=pd.products_id) join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on (p.products_id=p2c.products_id) left join " . TABLE_SPECIALS ." s on (s.products_id=p.products_id) left join " . TABLE_PRODUCTS_IMAGES . " pi on (pi.products_id=p.products_id) left join " . TABLE_PRODUCTS_GROUPS . " pg on (pg.products_id=p.products_id) left join " . TABLE_PRODUCTS_ATTRIBUTES_SETS_TO_PRODUCTS . " pas2p on (p.products_id=pas2p.products_id) where (pd.products_name like '%" . tep_db_input($search) . "%') or (p.products_model like '%" . tep_db_input($search) . "%') and (pd.language_id = '" . (int)$languages_id . "') and (p.products_id = p2c.products_id) and (p.products_id = pd.products_id) and (s.customers_group_id is null or s.customers_group_id=0) and (pg.customers_group_id=2 or pg.customers_group_id is null) and (pi.sort_order is null or pi.sort_order <2) and (pas2p.products_attributes_sets_id is null or pas2p.products_attributes_sets_id is not null) order by $order"); } Of course, I've modified the output to include sort-able columns for model, quantity, weight, MAP status, retail and SPPC pricing, retail specials price, attribute sets, a check for product thumbnail, large image, and that the image name matches the product name...and various other things that are handy to have available "at a glance". As far as table structure... products products_description products_groups products_images products_to_categories products_attribute_sets_to_products specials osC v2.3.1 MySQL v8.0.32 PHP v5.6.40 Installed addons: . Attribute Sets Plus .. Create Account & Manual Order Maker .. Customer Testimonials 2.3.4 .. Customer Blacklist .. Dynamic Info Pages .. FedEx Web Svcs v9 .. Filtered Sales Report .. Generic Box .. Google XML Sitemap SEO .. Maximum Order Value .. Modular Front Page .. Monthly Sales & Tax Report .. Multiple Products Manager .. Must Accept Terms & Conditions .. Order Editior .. PDF Customer Invoice .. Price in Cart Only .. Product Sort/Order .. Product Sort in Cart .. Quantity Discounts .. Restrict Delivery Methods .. SEO Header Tags - Reloaded .. Separate Pricing Per Customer .. Simpler Admin Session Length Control .. Sitemap SEO .. Show Free Ship + Modules .. Specials by Category for SPPC .. Store Mode (open|closed|maintenance) .. Store Pickup Shipping .. Theme Switcher .. Ultimate SEO URLs 5 Pro .. UPS XML Rates & Svcs 1.4 .. USPS methods 7.3.1 .. Who's Online Dashboard . Fixes: Add to cart -> 'product not found' : FIX Login issues with IE 11 : FIX Tools: Incredibly Handy: osC Xref Link to comment Share on other sites More sharing options...
MrPhil Posted June 20, 2015 Share Posted June 20, 2015 Using GROUP BY products_id might work for you. Look at http://www.mysqltutorial.org/mysql-distinct.aspx. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.