<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><span>Wouldn't it be easier to simply check if a value is set?</span></div><div><br><span></span></div><div><span>IE:</span></div><div><br><span></span></div><div><span>if($field3 == "HOUSE" and isset($searval3) and $searchval3 != "") {</span></div><div><span>&nbsp;... add the clause<br></span></div><div><span>}</span></div><div><br><span></span></div><div><span>That way you don't have an extra SQL bits. The extraneous "OR"s would just serve to confuse the database.</span></div><div><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span
 style="font-weight:bold;">From:</span></b> Jim Dahl &lt;jim.dahl@mail.co.douglas.mn.us&gt;<br> <b><span style="font-weight: bold;">To:</span></b> "geomoose-users@lists.osgeo.org" &lt;geomoose-users@lists.osgeo.org&gt; <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, May 23, 2012 8:40 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> [Geomoose-users] GeoMoose Search on Multi Fields with Implode Clause<br> </font> </div> <br>
<div id="yiv1964417161">

 
 
<style><!--
#yiv1964417161  
 _filtered #yiv1964417161 {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
#yiv1964417161  
#yiv1964417161 p.yiv1964417161MsoNormal, #yiv1964417161 li.yiv1964417161MsoNormal, #yiv1964417161 div.yiv1964417161MsoNormal
        {margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:"sans-serif";}
#yiv1964417161 a:link, #yiv1964417161 span.yiv1964417161MsoHyperlink
        {color:blue;text-decoration:underline;}
#yiv1964417161 a:visited, #yiv1964417161 span.yiv1964417161MsoHyperlinkFollowed
        {color:purple;text-decoration:underline;}
#yiv1964417161 span.yiv1964417161EmailStyle17
        {font-family:"sans-serif";color:windowtext;}
#yiv1964417161 .yiv1964417161MsoChpDefault
        {font-family:"sans-serif";}
 _filtered #yiv1964417161 {margin:1.0in 1.0in 1.0in 1.0in;}
#yiv1964417161 div.yiv1964417161WordSection1
        {}
--></style>

<div>
<div class="yiv1964417161WordSection1">
<div class="yiv1964417161MsoNormal">I have need to search on multiple fields and the following code works if I have a wildcard in all of the fields.&nbsp; If I take out a wildcard and do not enter anything in that field, the result is nothing found.&nbsp; Probably because the empty
 field doesn’t match the database for any entries.&nbsp; So what I would like to do is Make and OR with the field without a wild card and the other fields that have the AND.&nbsp; Hope this makes sense to someone.&nbsp; I credit Dan with the code for the implode clauses and
 it works great with the criteria of wild cards or have a pull down in the field that contains all the possible entries.&nbsp; HNUM is the field I would like to not have the wildcard. &nbsp;I have as many as ten fields, but show fewer for this example. &nbsp;THANKS.</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">$clauses = array();</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">if($field3 == "HNUM") {</div> 
<div class="yiv1964417161MsoNormal">array_push($clauses, "HNUM like '".$searchval3."'");</div> 
<div class="yiv1964417161MsoNormal">}</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">if($field4 == "STREET") {</div> 
<div class="yiv1964417161MsoNormal">array_push($clauses, "STREET like '%".$searchval4."%'");</div> 
<div class="yiv1964417161MsoNormal">}</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">if($field5 == "CITY") {</div> 
<div class="yiv1964417161MsoNormal">array_push($clauses, "CITY like '%".$searchval5."%'");</div> 
<div class="yiv1964417161MsoNormal">}</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">$all_clauses = implode(" AND ", $clauses);</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">$rs = $conn-&gt;Execute("SELECT * FROM housenum WHERE ".$all_clauses." ORDER BY ".$sort." ASC");</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">Jim Dahl, GISP</div> 
<div class="yiv1964417161MsoNormal">GIS Coordinator</div> 
<div class="yiv1964417161MsoNormal">Douglas County Public Works</div> 
<div class="yiv1964417161MsoNormal">526 Willow Dr</div> 
<div class="yiv1964417161MsoNormal">PO Box 398</div> 
<div class="yiv1964417161MsoNormal">Alexandria MN 56308</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
<div class="yiv1964417161MsoNormal">V 320-762-2933</div> 
<div class="yiv1964417161MsoNormal">&nbsp;&nbsp; 320-762-2999</div> 
<div class="yiv1964417161MsoNormal">F 320-762-2998</div> 
<div class="yiv1964417161MsoNormal"> &nbsp;</div> 
</div>
</div>

</div><br>_______________________________________________<br>Geomoose-users mailing list<br><a ymailto="mailto:Geomoose-users@lists.osgeo.org" href="mailto:Geomoose-users@lists.osgeo.org">Geomoose-users@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/geomoose-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/geomoose-users</a><br><br><br> </div> </div> </blockquote></div>   </div></body></html>