Home > Backend Development > PHP Tutorial > 求教用TP作类似淘宝那种多级筛选用if语句控制发现传一两个字段还好控制,传三个字段以上就不好控制了,筛选出来的数据就不对了。有什么好的方法吗

求教用TP作类似淘宝那种多级筛选用if语句控制发现传一两个字段还好控制,传三个字段以上就不好控制了,筛选出来的数据就不对了。有什么好的方法吗

WBOY
Release: 2016-06-13 12:22:43
Original
998 people have browsed it

求教用TP做类似淘宝那种多级筛选用if语句控制发现传一两个字段还好控制,传三个字段以上就不好控制了,筛选出来的数据就不对了。有什么好的方法吗?

<br />      //多级筛选<br />                     <br />                     $name=$_GET[pid];<br />                     $brand=$_GET[theme];<br />                     $carage=$_GET[price];<br />                     echo $carage;<br />  <br />                 <br />                     if($name="泵车" AND $brand="三一"){<br />                     $handmebuyinfo=M("handmebuyinfo");<br />                     $map['name']=$name;<br />                     $map['brand']=$brand;<br />                     //$map['carage']=$carage;<br />                     $row=$handmebuyinfo->where($map)->select();<br />                     dump($row);<br />                     }<br />                                        <br />                     if($name=='' OR $brand=='' OR $carage==''){<br />                     $handmebuyinfo=M("handmebuyinfo");<br />                     $map['name']=$name;<br />                     $map['brand']=$brand;<br />                     $map['carage']=$carage;<br />                     $map['_logic'] = 'OR';<br />                     $row=$handmebuyinfo->where($map)->select();<br />                     dump($row);<br />                     }<br />
Copy after login


------解决思路----------------------
$a = array(<br />  'a' => 1,<br />  'b' => '',<br />  'c' => 0,<br />);<br />print_r(array_diff($a, array('')));<br />print_r(array_diff($a, array('', 0)));
Copy after login
Array<br />(<br />    [a] => 1<br />    [c] => 0<br />)<br />Array<br />(<br />    [a] => 1<br />)<br /><br />
Copy after login
这样就不需要 if($name=='') 这样一个个判断了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template