
Originally Posted by
HiPCTech
The query returns double products when it finds more then 1 of the same product_id in the products_to_categories db table. I'll have to leave this until Sunday but I'd greatly appreciate any help. I know that God will help us solve this.
Hello everyone!
I've been working on this and the good Lord has guided me to the solution. I've tested it on a few pages and it works but it might still need some testing.
Here is the code that replaced lines 90-95.
PHP Code:
/* Change added by Iasmin Balaj on July 21, 2008. iasminb###################### */
if($str_pos_p2c===false && $str_pos_desc===false)
{
$sql = substr($sql,0,$add_pos).
" INNER JOIN (".TABLE_CATEGORIES_DESCRIPTION." cd, ".TABLE_PRODUCTS_TO_CATEGORIES." p2c)
ON (p2c.categories_id = cd.categories_id
AND p.products_id = p2c.products_id
AND cd.language_id=".$_SESSION['languages_id']."
AND cd.categories_description LIKE '%-".SITE_NAME."-%') ".
substr($sql,$add_pos);
}
// put the new query in the WHERE statement. Find the categories description for this site, match it to p2c and then to the p_id.
elseif($str_pos_p2c!==false && $str_pos_desc!==false) {
$str_pos_where = strpos($sql,'where') + 5;
$sql = substr($sql,0,$str_pos_where).
" \n(cd.language_id=".$_SESSION['languages_id']."
AND cd.categories_description LIKE '%-".SITE_NAME."-%'
AND p2c.categories_id = cd.categories_id
AND p.products_id = p2c.products_id)\n ".
substr($sql,$str_pos_where);
}
// put the new query in the WHERE statement IF p2c is declared but CAT_DESC is not.
elseif($str_pos_p2c!==false) {
$str_pos_where = strpos($sql,'where');
$sql = substr($sql,0,$str_pos_where).
', '.TABLE_CATEGORIES_DESCRIPTION.' cd '.
substr($sql,$str_pos_where);
$str_pos_where = strpos($sql,'where') + 5;
$sql = substr($sql,0,$str_pos_where).
' (p2c.categories_id = cd.categories_id AND p.products_id = p2c.products_id AND cd.language_id=1 AND cd.categories_description LIKE \'%'.SITE_NAME.'%\') AND '.
substr($sql,$str_pos_where);
}
//
else {
$sql = substr($sql,0,$add_pos).
" INNER JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd
ON (p.master_categories_id = cd.categories_id
AND cd.language_id=".$_SESSION['languages_id']."
AND cd.categories_description LIKE '%-".SITE_NAME."-%') ".
substr($sql,$add_pos);
$str_pos_where = strpos($sql,'where') + 5;
$sql = substr($sql,0,$str_pos_where).
" \n(p.products_id = p2c.products_id
AND p.master_categories_id = p2c.categories_id)\n ".
substr($sql,$str_pos_where);
}
I hope that this helps and please let me know if there are any errors.
God bless you,
Iasmin
Bookmarks