OR Search

Hi!!Guys.Are you well?

Now,I’m person in nedd.

Therfore,help me,please...

$keyword = mb_convert_kana($search_word, 's'); // 全角スペースを半角スペースに変換

        $keyword = preg_replace('/\s+/', ' ', $keyword);//連続する半角スペースを1つの半角スペースへ

        $split_ary_keyword = explode(" ",$keyword);

        foreach ($split_ary_keyword as $word) {
            $d_products = D_products::find(array(
                                "text_search LIKE :keyword:",
                                "bind"=>array(
                                    'keyword'=> '%' . $word . '%'
                                )
                            ));
        }

I want to convert to the same result is obtained with the OR search of SQL.



67.6k

something like this maybe ?


$words = [];
        $conditions = "";
        $bind = [];
        foreach ($words AS $i => $word){
            if ($word == ""){
                continue;
            }

            $conditions.="word = ?".$i. " OR ";
            $bind[$i] = "%".$word."%";
        }

        if ($conditions == ""){
            //throw bla bla bla
        }

        MyModel::find([
            "conditions" => rtrim($conditions, " OR "),
            "bind" => $bind
        ]);
edited Jan '16

Good Morning in Japan. Thank you for your kindness Izo!!

$keyword = mb_convert_kana($search_word, 's'); // 全角スペースを半角スペースに変換

$trim_space_keyword = preg_replace('/\s+/', ' ', $keyword);//連続する半角スペースを1つの半角スペースへ

$split_ary_keyword = explode(" ",$trim_space_keyword); 

$conditions = "";
$bind = [];
foreach ($split_ary_keyword AS $i => $word){
if ($word == ""){
continue;
}

$conditions.="text_search Like ?".$i. " OR ";
$bind[$i] = "%".$word."%";
}

if ($conditions == ""){
//throw bla bla bla
}

$d_products = MyModel::find([
"conditions" => rtrim($conditions, " OR "),
"bind" => $bind
]);

It's a result.

See you.



67.6k

i guess it is working, you can accept your reply as answer, so post can be marked as solved.

Cheers!