amwd07 Posted April 25, 2009 Share Posted April 25, 2009 I am trying to filter the results query before retuning the function <?php $queryResults = ' SELECT DISTINCT SQL_CALC_FOUND_ROWS p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, t.`rate`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON p.`id_product` = pa.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') LEFT OUTER JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).') LEFT JOIN `'._DB_PREFIX_.'tax` t ON (p.`id_tax` = t.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE cp.`id_category` = '.intval($currentCategory).' AND p.`active` = 1 AND '.(($range == false && $selection && sizeof($selection)) ? ' p.`id_product` IN ('.implode(',', array_map('intval', $selection)).')' : $whereBy).' AND a.`id_attribute` IN (49,97,110) // this does not filter '.($orderBy ? 'ORDER BY '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.intval(($pageNumber - 1) * $pageSize).','.intval($pageSize); $result = Db::getInstance()->ExecuteS($queryResults) or die(mysql_error()); $total = Db::getInstance()->getValue('SELECT FOUND_ROWS()'); $result = Db::getInstance()->ExecuteS($queryResults) or die(mysql_error()); ?> this would return 3 results which is correct but when I try to add a second array map into the above query this still returns 3 results, there should only be one result, so I have come to the conclusion this can not be done within SQL so I would like to filter my result from the DB query $result = /// $result['id_attribute'] filter array('49','97','110','95'); = 1 product then return $result; (Previously used SQL) Link to comment https://forums.phpfreaks.com/topic/155574-filter-mysql-result/ Share on other sites More sharing options...
amwd07 Posted April 25, 2009 Author Share Posted April 25, 2009 I believe I may be able to do something like this before the query but not sure what I can put in the filterGroups callback function? $selection = array_filter($selection,$this->filterGroups); Link to comment https://forums.phpfreaks.com/topic/155574-filter-mysql-result/#findComment-818747 Share on other sites More sharing options...
amwd07 Posted April 26, 2009 Author Share Posted April 26, 2009 ok I now feel alone with this issue although defferently moving forward, have now found the right solution to my problem but need assistance implementing. The problem is I can not loop through the product ID's, this is because it would seem I can only use 1 foreach loop for my resultRtn array, I need to be able to loop through the product ID's so I can set these as keys for example array(pID => attID) // $attArray = array(); // foreach($newExp as $attID) // foreach($selection as $pID) // Method 1 $attArray = array(); foreach($newExp as $attID) { $resultRtn = array( id_product => 'return ( $att["id_product"] == "'.$selection.'" );', id_attribute => 'return ( $att["id_attribute"] == "'.$attID.'" );', ); $attUsr = create_function('$att', $resultRtn); $filtered_results = array_filter($selAtt, $attUsr); $attArray[] = $attID; $count = count($filtered_results); echo "Attribute Found ".$attID.": (".$count.")<br \>"; } print_r($attArray); Link to comment https://forums.phpfreaks.com/topic/155574-filter-mysql-result/#findComment-819552 Share on other sites More sharing options...
amwd07 Posted April 26, 2009 Author Share Posted April 26, 2009 ok I now feel alone with this issue although defferently moving forward, have now found the right solution to my problem but need assistance implementing. The problem is I can not loop through the product ID's, this is because it would seem I can only use 1 foreach loop for my resultRtn array, I need to be able to loop through the product ID's so I can set these as keys for example array(pID => attID) <?php // $selAtt = FilterSearch::getProductsAttributesID($expr); // example output of this array // [0] => Array ( [id_product] => 31 [id_attribute] => 39 ) // [1] => Array ( [id_product] => 31 [id_attribute] => 48 ) // [2] => Array ( [id_product] => 31 [id_attribute] => 63 ) // [3] => Array ( [id_product] => 31 [id_attribute] => 96 ) // $attArray = array(); // foreach($newExp as $attID) // foreach($selection as $pID) // Method 1 $attArray = array(); foreach($newExp as $attID) { $resultRtn = array( id_product => 'return ( $att["id_product"] == "'.$selection.'" );', // Notice: Use of undefined constant id_product - assumed 'id_product' id_attribute => 'return ( $att["id_attribute"] == "'.$attID.'" );', // This one works fine ); $attUsr = create_function('$att', $resultRtn); $filtered_results = array_filter($selAtt, $attUsr); $attArray[] = $attID; $count = count($filtered_results); echo "Attribute Found ".$attID.": (".$count.")<br \>"; } print_r($attArray); ?> Link to comment https://forums.phpfreaks.com/topic/155574-filter-mysql-result/#findComment-819554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.