DSC_0196_1

Tuesday, June 05, 2007

1052 - Column 'products_id' in from clause is ambiguous

Recently I tried to set up the "Separate Price Per Customer" contribution of Oscommerce for my wife's wholesale tea business, Jaya Teas. Setting up the contrib itself was not a problem, and I thought all was well with the site. I went in and created my own account, and was pleased with the effect. Then, I tried to implement the "retail to wholesale conversion of my account, and to my horror, as soon as I logged in as a wholesale customer, the entire right side of the website was disfigured with following error:
1052 - Column 'products_id' in from clause is ambiguous

select p.products_id, pd.products_name, IF(pg.customers_group_price IS NOT NULL,pg.customers_group_price, p.products_price) as products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from products p, products_description pd, specials s LEFT JOIN products_groups pg using (products_id, customers_group_id) where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '1' and s.status = '1' and s.customers_group_id= '1' order by s.specials_date_added desc limit 10

[TEP STOP]

You can see this better in this image


PANIC!!!

As is natural, panic was my first reaction. I had had the wholesale site up for a while, and if I had paid attention to this before, I would have noticed this problem, but this was the first time I was noticing it. What had caused this? I had not made any changes recently, so what could have caused it? After some thinking I realized that this problem may have been caused due to the installation of the "Separate Price Per Customer" contrib, and that calmed me down a bit. I knew that once the source of the problem had been identified, the solution could not be too far away.

Google to my rescue:
I googled the query "1052 - Column 'products_id' in from clause is ambiguous", which gave me confirmation that indeed the problem was with this contrib. One particular entry was very specific about the probem and its solution.

It appears that the problem is with the syntax of "product_id" in a file called specials.php in
catalog/includes/boxes/specials.php

The entire block of code is in this file, and just sleuthing the problem was beyond me, but Jan Zonjee, a PHP expert figured it out that for some reason, MySQL isn't able to recognize what product_id stands for. So, in this code, we need to be specific about it. This is done by replacing
using (products_id, customers_group_id)

with
on (s.products_id = pg.products_id and s.customers_group_id = pg.customers_group_id)

I quickly FTPd to the directory, made a copy of specials.php file (as a back up just in case something goes wrong again), and then implemented the change.
Lo and behold, the error is gone!!

I love open source software! Thank you Jay Zonjee!

Labels: , ,

0 Comments:

Post a Comment

<< Home