You are here:  » Regarding comparison by sku/isbn instead of name

Support Forum



Regarding comparison by sku/isbn instead of name

Submitted by apa on Wed, 2008-11-05 14:53 in

You gave the below examble in the tread http://www.pricetapestry.com/node/775

The code change does so that comparisons are made by sku first and then by name. I have implementet the same thing in my book comparison site but i would really prefer that comparisons where only made by and if an isbn exist. In my case - two books of the same name but in paperback and hardback versions would have different isbn numbers but the same name of course. They would be compared by the titel of the book in the below examble, but that would not be correct since the hardback is of course a different item.

What should the code look like to just compare by sku/isbn?

Kind regards,
Anders

The existing code in products.php is as follows:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' ORDER BY price LIMIT ".$config_resultsPerPage;
    $numRows = database_querySelect($sql,$rows);

You need to modify this along the lines of the following; replacing "sku" with whatever field name you are using in your database:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($q)."' LIMIT 1";
    database_querySelect($sql,$rows);
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($rows[0]["name"])."' OR sku = '".database_safe($rows[0]["sku"])."' ORDER BY price LIMIT ".$config_resultsPerPage;
    $numRows = database_querySelect($sql,$rows);

Submitted by support on Wed, 2008-11-05 15:04

Hello Anders,

The way Price Tapestry works (the product name being unique) it wouldn't make any difference if the modified code was changed to compare on sku only, since the initial look-up has to be by product name as this is all that is passed to products.php...

For completeness however, the following line of the modification:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name = '".database_safe($rows[0]["name"])."' OR sku = '".database_safe($rows[0]["sku"])."' ORDER BY price LIMIT ".$config_resultsPerPage;

...could become:

$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE sku = '".database_safe($rows[0]["sku"])."' ORDER BY price LIMIT ".$config_resultsPerPage;

...but it's the fact that SKU has already been picked from the same table based on a WHERE name = ... clause that means it shouldn't make any difference to the results (if all products have an SKU).

Hope this makes sense!

Cheers,
David.