在Query Builder中的WHERE子句中使用`LIKE`

时间:2013-08-04 09:36:33

标签: php mysql laravel where-clause query-builder

public function ajax_quick_browse($keyword) 
{
    if (strlen($keyword) > 3) 
    {
        $results = DB::table("products")
                ->where("full_name", "LIKE", "%{$keyword}%")
                ->take(3)
                ->get();

        if ($results) 
        {
            $output = "";
            foreach ($results as $result) 
            {
                $image_link = $result->brand_name . "-" . str_replace(" ", "-", $result->product_name) . "-" . "thumbnail";
                $image_link = URL::to("/") . "/assets/uploads/" . strtolower(str_replace(" ", "-", $image_link)) . ".jpg";
                $spec_link = URL::to("/") . "/specification/" . str_singular($result->category_name) . "/{$result->brand_name}/{$result->product_name}/";
                $spec_link = strtolower(str_replace(" ", "-", $spec_link));
                $output .= "<a class='product' href='{$spec_link}'>
                        <ul>
                            <li class='image'><img src='{$image_link}' height='105' width='75' alt='Galaxy S4'></li>
                            <li class='brand'>{$result->brand_name}</li>
                            <li ='model'>{$result->product_name}</li>
                            <li class='status'>{$result->status}</li>
                            <li class='price'>{$result->price} <span class='green'>PKR</span></li>
                        </ul>
                        </a>";
            }
            echo $output;
        } 
        else 
        {
            echo "No Results";
        }
    } 
    else 
    {
        return NULL;
    }
}

列名为full_name,其中包含行记录nokia lumia 920。现在问题是我有三种类型的关键字如图所示..

  1. “诺基亚”
  2. “的Lumia”
  3. “920”
  4. 当我用上述两个关键字查询时,我得到了结果。但是当我用“920”(最后一个)关键字查询时,我得到“没有结果”。

    我在Laravel Framework中使用查询构建器。

0 个答案:

没有答案