【发布时间】:2018-05-04 19:18:44
【问题描述】:
我使用代码通过 $_GET 进行过滤
$this['painting'] = Painting::
where('p_price',$p_price)->
where('p_created',$p_created) ->
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
网址是mysite/page.php?type_id=3&p_created=1996 一切正常。
但是如果我有一些空的参数我没有结果。例如 url 是 mysite/page.php?type_id=&p_created=1996 或 url 是 mysite/page.php?type_id=3&p_created=return 空字符串
现在我使用类似的东西
if (!$p_created and !$type_id){
$this['painting'] = Painting::
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif (!$p_created and $type_id){
$this['painting'] = Painting::
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif ($p_created and !$type_id){
$this['painting'] = Painting::
where('p_created',$p_created) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
elseif ($p_created and $type_id){
$this['painting'] = Painting::
where('p_created',$p_created) ->
where('type_id',$type_id) ->
whereHas('artist', function($q)
{
$q->where('artist_slug', '=', $this->param('slug'));
})->get();
}
我该如何解决?
【问题讨论】:
标签: php mysql octobercms