基于产品标题的汽车相关或类似产品

时间:2015-06-18 12:54:44

标签: php mysql oop pdo

如果产品库存少于15,我试图创建一个类似(相关)产品系统的自动显示器 相关产品根据主要产品的名称显示 一些类似的产品被复制到其他产品中 什么是避免这种情况的最佳解决方案?

function getRecommendedList($product, $brand, $cod, $code_array, $last_code){
    global $pdoconnect;
    $image         = new Image();
    $cur_page      = $_GET['page'];
    $last_code     = array();

    $product_terms = explode(' ', $product);
    $case          = " LCASE(p.titlu) LIKE '%" .strtolower(implode("%' AND LCASE(p.titlu) LIKE '%", $product_terms))."%'";

    $stmt          = $pdoconnect->prepare("SELECT 
                               p.id AS pid, p.titlu AS titlu, 
                               p.alias AS alias, p.gramaj AS gramaj,
                               p.prettotal AS prettotal, p.cod AS cod,
                               p.poza AS poza, p.categorie AS categorie,
                               c.seo AS seo 
                               FROM produse p
                               INNER JOIN categorii c 
                              ON p.categorie=c.id 
                              WHERE ".$case." AND p.vizibil='1' 
                              AND p.brand=:brand 
                              AND p.cod !=:cod 
                              AND p.cod 
                              NOT IN ('" . implode($code_array, "', '") . "') 
                              AND p.cod 
                              NOT IN ('" . implode($last_code, "', '") . "')");
    $stmt->bindValue(':brand', $brand, PDO::PARAM_STR);
    $stmt->bindValue(':cod', $cod, PDO::PARAM_STR);
    $stmt->execute();

    $total_recommended  = $stmt->rowCount();
    $recommended        = $stmt->fetchAll(PDO::FETCH_ASSOC);
    // echo $stmt->debugDumpParams();

    $max_results        = 3;

    /*Check if there are more than 3 results for the product*/
    if($total_recommended > $max_results){
        $total_recommended = $max_results;
    }

    if($total_recommended > 0){
        for ($i=0; $i < $total_recommended; $i++) { 
            $produs['pid'][]          = $recommended[$i]['pid'];
            $produs['titlu'][]        = ucwords(strtolower($recommended[$i]['titlu']));
            $produs['cod'][]          = $recommended[$i]['cod'];
            $produs['prettotal'][]    = $recommended[$i]['prettotal'];
            $produs['gramaj'][]       = $recommended[$i]['gramaj'];
            $produs['categorie'][]    = $recommended[$i]['categorie'];
            $produs['alias'][]        = $recommended[$i]['alias'];
            $produs['seo'][]          = $recommended[$i]['seo'];

            if(file_exists(PATH . "/media/images/".$recommended[$i]['poza'])){
                $produs['foto'][]  = 
                WEBSITE . "/media/images/".$image->resize($recommended[$i]['poza'], 45, 45);
            } else {
                $produs['foto'][]  = 
                WEBSITE . "/media/images/".$image->resize('www.jpg', 45, 45);
            }
        }

        return $produs;
    }else{
        return false;
    }
}

该函数用于foreach循环

    if($items['stoc'] < 15){
        $smartyProduse['recommended'][] =
        getRecommendedList($items['titlu'], $items['brand'], $items['cod'], $code_array[0]);    
    }

enter image description here

0 个答案:

没有答案