Hi Dave,
Thank you for the update on cache tables works a treat!
I have created a new sql table with known brands list i wanted match brands from this table to merchant brands if brand not found then try to match against product name if found to update brands field with the matched brand name from brands list if no match found to set it to unbranded?
or would it be better to create a function for this with an str replace? i am unsure where to start with this one?
Kind Regards
Darren
Hi Dave,
Thank you very much for the code but unfortunately i get an error when trying to run
PHP Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in scripts/brand_matching_code.php on line 12
Kind Regards
Darren
Hi Darren,
The syntax was slightly wrong - have a go with:
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".database_safe($row["brand"])."' WHERE name LIKE '%".database_safe($row["brand"])."%' AND brand = ''";
Cheers,
David.
Hi Darren,
Try something like this; I'm assuming your new table is called just "brands" and simply has an id and brand field. If not, simply modify as appropriate...
<?php
require("includes/common.php");
$sql = "SELECT * FROM `".$config_databaseTablePrefix."brands`";
database_querySelect($sql,$rows);
foreach($rows as $row)
{
// is this brand NOT in the brand_cache table?
$sql = "SELECT * FROM `".$config_databaseTablePrefix."brand_cache` WHERE brand='".database_safe($row["brand"])."'";
if (!database_querySelect($sql,$result))
{
// so update brand field of any products containing the brand name
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".database_safe($row["brand"])."' WHERE name LIKE '%".database_safe(".$row["brand"].")."%'";
database_queryModify($sql,$result);
}
}
print "Done.";
?>
You may however not want to update the brand field if there is already a value, in which case replace the UPDATE line with:
$sql = "UPDATE `".$config_databaseTablePrefix."products` SET brand='".database_safe($row["brand"])."' WHERE name LIKE '%".database_safe(".$row["brand"].")."%' AND brand = ''";
Cheers,
David.