laravel 5搜索查询问题

时间:2015-08-03 06:07:14

标签: php mysql laravel-5

我需要搜索从DB表中过滤不同的列,这些过滤列是groupA,groupb和groupC,每列在db表中都有以下值high, low, moderate

但前端用户具有名为“none”的其他值,但该值不包含在数据库中。

这是我当前的查询

  public function show($groupA, $groupB, $groupC)
    {
        $FodMaps = FodMap::where('groupA', '=', $groupA)->where('groupB', '=', $groupB)->where('groupC', '=', $groupC)->get();
        return $FodMaps;


    }

我想要的是如果用户搜索的值不包含在db(高/低/中等)中,它应该搜索除了具有不匹配值的列之外的其他列

ex:http://url/api/fodmap/groupA=low/groupB=low/groupC=high

如果用户输入上述方式,则应根据值

显示结果

但如果用户输入如下

http://url/api/fodmap/groupA=low/groupB=low/groupC=none

因为groupC列中的“none”值没有退出,所以只搜索其他两列而不考虑groupC的值

请咨询

1 个答案:

答案 0 :(得分:0)

您可以像这样动态添加查询条件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/mainView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#EEEEEE"
    android:orientation="vertical">

    ...

</LinearLayout>
相关问题