Best way to find duplicate products by model number and display the top level category name they are in?
#1
Posted 09 January 2012, 22:16
As the title of the thread suggests I am trying to find the best way to find duplicate products by model number and display the top level category name they are in.
As the store I am working on will sell spare parts the same spare part may also be present in more than 1 category so my ultimate goal is to find all the duplicates and list them on the product listing page along side the product.
I have found various queries that find duplicates but only by product_id which is fine but the product_model is not present in a table such as products_to_categories.
Can any of the guru's suggest a query that I can use for this?
Thanks
Mark
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#2
Posted 10 January 2012, 00:38
#3
Posted 11 January 2012, 00:02
$product_to_category_query = tep_db_query("select p.products_id, products_model from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'");
close or miles away?
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#4
Posted 11 January 2012, 20:39
I now have come up with this
$product_to_category_query = tep_db_query("SELECT products_id, products_model FROM " . TABLE_PRODUCTS . " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " ON products_model = categories_id'");
However this results in this error:
Quote
SELECT products_id, products_model FROM products LEFT JOIN products_to_categories ON products_model = categories_id'
[TEP STOP]
Please help!
Thanks
Mark
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#5
Posted 11 January 2012, 22:21
Why is there a single quote at the end of the line, also left joins need brackets,
SELECT products_id, products_model FROM (products) LEFT JOIN products_to_categories ON products_model = categories_id
HTH
G
Virus Threat Scanner
My Contributions
Basic install answers.
Click here for Contributions / Add Ons.
UK your site.
Site Move.
Basic design info.
For links mentioned in old answers that are no longer here follow this link Useful Threads.
If this post was useful, click the Like This button over there ======>>>>>.
#6
Posted 11 January 2012, 23:10
geoffreywalton, on 11 January 2012, 22:21, said:
Why is there a single quote at the end of the line, also left joins need brackets,
SELECT products_id, products_model FROM (products) LEFT JOIN products_to_categories ON products_model = categories_id
HTH
G
Hi Geoffrey,
Thanks for the reply. I have taken what you said and applied it then I got the 'ambiguous' error so obviously it was asking me it has found a products_id in both the products and products_to_categories tables and I need to specify which one.
So I changed the code to
$product_to_category_query = tep_db_query("SELECT products_id FROM (" . TABLE_PRODUCTS . ") p LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id");
and now I am well stuck with
Quote
SELECT p.products_id FROM (products) LEFT JOIN products_to_categories p2c where p.products_id = p2c.products_id
[TEP STOP]
not expecting the query written for me just a hand to wipe the tears lol
Thanks
Mark
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#7
Posted 12 January 2012, 01:18
SELECT p.products_id, p.products_model, p2c.categories_id FROM products AS p LEFT JOIN products_to_categories AS p2c ON p2c.products_id = p.products_id
Didn't check the database for actual column names so those maybe off, but that should put you on the right track.
#8
Posted 12 January 2012, 14:16
Check out w3schools.com for more info on mysql
HTH
G
Virus Threat Scanner
My Contributions
Basic install answers.
Click here for Contributions / Add Ons.
UK your site.
Site Move.
Basic design info.
For links mentioned in old answers that are no longer here follow this link Useful Threads.
If this post was useful, click the Like This button over there ======>>>>>.
#9
Posted 12 January 2012, 19:26
NodsDorf, on 12 January 2012, 01:18, said:
SELECT p.products_id, p.products_model, p2c.categories_id FROM products AS p LEFT JOIN products_to_categories AS p2c ON p2c.products_id = p.products_id
Didn't check the database for actual column names so those maybe off, but that should put you on the right track.
Thanks guys that did the trick
Now the real trouble starts as I need a way of drilling down to show the name of the 3rd category in the tree in all top level categories (Sub Category3) i.e.
Top Level Category 1
|---------->Sub Category 1
|---------->Sub Category 2
|---------->Sub Category 3
Top Level Category 2
|---------->Sub Category 1
|---------->Sub Category 2
|---------->Sub Category 3
etc etc etc.....
Thanks
Mark
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#10
Posted 12 January 2012, 23:08
$product_to_category_query = tep_db_query("SELECT distinct p.products_id, p.products_model, cd.categories_name, p2c.categories_id FROM products AS p LEFT JOIN products_to_categories AS p2c ON p2c.products_id = p.products_id LEFT JOIN categories_description AS cd ON cd.categories_id = p2c.categories_id");
Mark
Edited by PupStar, 12 January 2012, 23:23.
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#11
Posted 13 January 2012, 00:31
So it looks like this maybe your issue....
You have the same product in multiple categories right?
So you can't use SELECT DISTINCT because you now have eliminated all the duplicates.
Your results indicate that the SELECT is getting an array and moving to the first / last level of it to give you results. Try getting the data you want straight through SQL then move to the processing of it in PHP. Without knowing what kind of can of worms you opened I'm not sure I can be much more help.
But I do hope it helps,
Don
#12
Posted 13 January 2012, 19:06
NodsDorf, on 13 January 2012, 00:31, said:
So it looks like this maybe your issue....
You have the same product in multiple categories right?
So you can't use SELECT DISTINCT because you now have eliminated all the duplicates.
well sort of, same products_model different product_id but essentially yes same product in multiple categories.
Quote
But I do hope it helps,
Don
ok this is the code that I have in the modified product_listing file maybe you can make good of the query better than me urgh
<form name="cart_multi" method="post" action="<?php echo tep_href_link(FILENAME_SHOPPING_CART, tep_get_all_get_params(array('action')) . 'action=add_multi', 'NONSSL'); ?>">
<div class="contentText">
<?php
$prod_list_contents = '<div style="clear: both; padding:5px;"></div>' .
'<div class="contentContainer">' .
' <div class="ui-widget-header ui-corner-top">' .
' <table border="0" width="100%" cellspacing="0" cellpadding="0">' .
' <tr>';
for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
$lc_align = '';
switch ($column_list[$col]) {
case 'PRODUCT_LIST_MEDIACAT_PART_NO':
$lc_text = TABLE_HEADING_PARTS_ID;
$lc_align = 'right';
break;
case 'PRODUCT_LIST_MODEL':
$lc_text = TABLE_HEADING_MODEL;
$lc_align = 'center';
break;
case 'PRODUCT_LIST_NAME':
$lc_text = TABLE_HEADING_PRODUCTS_DESCRIPTION;
$lc_align = 'center';
break;
case 'PRODUCT_LIST_MEDIACAT_QUANTITY':
$lc_text = TABLE_HEADING_MEDIACAT_QUANTITY;
$lc_align = 'left';
break;
case 'PRODUCT_LIST_QUANTITY':
$lc_text = TABLE_HEADING_QUANTITY;
$lc_align = 'right';
break;
case 'PRODUCT_LIST_PRICE':
$lc_text = '';
$lc_align = 'right';
break;
}
$prod_list_contents .= ' <td class="partsfindercolumn" ' . (tep_not_null($lc_align) ? ' align="' . $lc_align . '"' : '') . '>' . $lc_text . '</td>';
}
$prod_list_contents .= ' <td width="19%"> </td></tr>' .
' </table>' .
' </div></div>';
if ($listing_split->number_of_rows > 0) {
$product_to_category_query = tep_db_query("SELECT p.products_id, p.products_model, cd.categories_name, p2c.categories_id FROM products AS p LEFT JOIN products_to_categories AS p2c ON p2c.products_id = p.products_id LEFT JOIN categories_description AS cd ON cd.categories_id = p2c.categories_id");
$product_to_category = tep_db_fetch_array($product_to_category_query);
$rows = 0;
$listing_query = tep_db_query($listing_split->sql_query);
$prod_list_contents .= ' <div style="padding-bottom:16px;" class="ui-widget ui-widget-content-parts-finder ui-corner-bottom">' .
' <table border="0" width="94%" cellspacing="0" cellpadding="2" align="center" class="striped">';
while ($listing = tep_db_fetch_array($listing_query)) {
$rows++;
$prod_list_contents .= '<tr>';
for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
switch ($column_list[$col]) {
case 'PRODUCT_LIST_MEDIACAT_PART_NO':
$prod_list_contents .= ' <td> </td><td width="15px" align="center" style="font-weight:bold; background-color: #c9c9c9;">' . $listing['mediacat_part_no'] . '</td>';
break;
case 'PRODUCT_LIST_MEDIACAT_QUANTITY':
$prod_list_contents .= ' <td width="6%" align="center">' . $listing['products_mediacat_quantity'] . '</td>';
break;
case 'PRODUCT_LIST_MODEL':
$prod_list_contents .= ' <td width="20%" align="center">' . $listing['products_model'] . '</td>';
break;
case 'PRODUCT_LIST_NAME':
if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {
$prod_list_contents .= ' <td width="40%" style="padding-left: 2px">' . $listing['products_name'] . ' <a class=info href="#" onclick="return false">info<span><b>' . $product_to_category['categories_name'] . '</b></span></a></td>';
} else {
$prod_list_contents .= ' <td width="40%" style="padding-left: 2px">' . $listing['products_name'] . ' <a class=info href="#" onclick="return false">info<span><b>' . $product_to_category['categories_name'] . '</b></span></a></td>';
}
break;
case 'PRODUCT_LIST_PRICE':
if (tep_not_null($listing['specials_new_products_price'] > '0')) {
$prod_list_contents .= '<td width="20%" align="center"><del>' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>';
}
else if ($listing['products_price'] == 0){
$prod_list_contents .= '<td width="50%" align="center" colspan="2" class="smallText"><a href="' . tep_href_link(FILENAME_CONTACT_US) . '">' . TEXT_CALL_FOR_PRICE . '</a></td>';
} else {
$prod_list_contents .= '<td width="14%" align="center">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</td>';
}
break;
case 'PRODUCT_LIST_BUY_NOW':
if (tep_not_null($listing['products_price'] > '0')) {
$qty_array=array();
$qty_array[] = array('id' => '00', 'text' => 'Qty');
for($i=1; $i<=20; $i++){
if(strlen($i)!= 1){
$j = '' . $i;
} else {
$j = $i;
}
$qty_array[] = array('id' => $j, 'text' => $j); }
$prod_list_contents .= '<td width="20%" align="center">' . TEXT_QTY . ' ' . tep_draw_pull_down_menu('add_id['.$number_of_products.']', $qty_array, $i) . tep_draw_hidden_field('products_id['.$number_of_products.']', $listing['products_id']) . '</td>';
}else{
$prod_list_contents .= ' ';
}
break;
}
}
$prod_list_contents .= ' </tr>';
}
$prod_list_contents .= ' </table>' .
'</div>';
echo $prod_list_contents;
} else {
?>
<p><?php echo TEXT_NO_PRODUCTS; ?></p>
<?php
}
?>
<div class="contentContainer">
<div class="ui-widget buttonSet" style="padding-top:10px;">
<span class="buttonAction"><?php echo '<b>' . TEXT_ENTER_QUANTITY . TEXT_YOU_REQUIRE . '</b> ' . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></span>
</div>
</div>
</form>
<div style="clear: both; padding:8px;"></div>
<div class="contentContainer">
<div class="ui-widget ui-widget-content ui-corner-all contentText" style="padding: 10px; background: #f4f4f4 url(images/main-bg.png); background-repeat: repeat-xy; font-style: italic;">
<div class="contentText"><?php echo TEXT_PARTS_FINDER_TIP;?>
</div>
</div>
</div>
</div>
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#13
Posted 14 January 2012, 15:50
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#14
Posted 14 January 2012, 18:21
Hope somebody else can point you in the right direction.
#15
Posted 14 January 2012, 18:38
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#16
Posted 21 January 2012, 13:58
I am still having no joy in getting this sorted.
One last attempt at asking for help before I dump this out of my product listing for good as I am jiggered if I can figure it out urgh
Thanks
Mark
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#17
Posted 22 January 2012, 01:25
Most Important: Header Tags SEO - Ultimate SEO V 2.2d
All SEO Addons: Recommended SEO Addons
Support Links:
Finding relevant link exchanges - Headers Already Sent - What does it cost? -What's my version? - How to change titles? - Preventing HotLinking
#18
Posted 22 January 2012, 11:15
Regards,
Patrick Luursema
#19
Posted 28 January 2012, 15:24
// Return a category's name
function tep_get_category_name($categories_id,
$language = '') {
global $languages_id;
if (empty($language)) $language = $languages_id;
$categories_query =
tep_db_query("select categories_name from " .
TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" .
(int)$categories_id . "' and language_id = '" .
(int)$language . "'");
$categories = tep_db_fetch_array($categories_query);
return $categories['categories_name'];
}
// Construct a category path to the product in names
function tep_get_product_path_names($products_id) {
$cat_namePath = '';
$category_query =
tep_db_query("select p2c.categories_id from " .
TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . "
p2c where p.products_id = '" . (int)$products_id . "' and
p.products_status = '1' and
p.products_id = p2c.products_id limit 1");
if (tep_db_num_rows($category_query)) {
$category = tep_db_fetch_array($category_query);
$categories = array();
tep_get_parent_categories($categories,
$category['categories_id']);
$categories = array_reverse($categories);
$cat_namePath =
tep_get_category_name(implode('_', $categories));
if (tep_not_null($cat_namePath)) $cat_namePath .= '->';
$cat_namePath .=
tep_get_category_name($category['categories_id']);
}
return $cat_namePath;
}
However this returns the top level category name and the category that the product is in for example:
Quote
The actual full category path is:
Quote
Ideally I would like it to just return the second subcategory name in this example being 'ms170'
Is anyone willing to give this a shot for me?
Thanks
Mark
Edited by PupStar, 28 January 2012, 15:25.
Join Us On Facebook & Twitter Infobox
Contributions currently installed into osCommerce 2.3.1
- Ajax Attributes Manager
- CKEditor
- Column Listing with smart column (modified)
- Documents Manager
- Easy Map
- EasyPopulate v2_76i_231
- Mindsparx Specials
- Mindsparx Admin
- OTF Auto Thumbnailer v2.4
- Star Product v1.6 + Mindsparx Pimped version
- Ultimate SEO Urls
- Who's Online Enhancement
- Printer Filter V1.7 (modified)
- Info Pages Unlimited v2.07
- Google Feeder V2.6
- Year Make Model
#20
Posted 28 January 2012, 22:33
tep_db_query="select pc.categories_name, p.products_id from products p join products_to_categories p2c using(products_id) join categories c using(categories_id) join categories_description pc on ( c.parent_categories_id = pc.categories_id and pc.language_id = '" . (int)$language . "' ) where products_model = '" . $listing['products_model'] ."' and p.products_id <> '" . $listing['products_id'] . "' ";
untested code, so syntax needs to be checked, but the logic of this is, for a given product being listed, it would show the parent category name, and products_id with the same model, (except for the current product being listed)
HTH
Carine Bruyndoncx
KEUKENLUST, Everything but the kitchensink !














