[Geomoose-users] GeoMoose Search on Multi Fields with Implode Clause

Jim Dahl jim.dahl at mail.co.douglas.mn.us
Wed May 23 09:40:56 EDT 2012


I have need to search on multiple fields and the following code works if I have a wildcard in all of the fields.  If I take out a wildcard and do not enter anything in that field, the result is nothing found.  Probably because the empty field doesn't match the database for any entries.  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.  Hope this makes sense to someone.  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.  HNUM is the field I would like to not have the wildcard.  I have as many as ten fields, but show fewer for this example.  THANKS.


$clauses = array();

if($field3 == "HNUM") {
array_push($clauses, "HNUM like '".$searchval3."'");
}

if($field4 == "STREET") {
array_push($clauses, "STREET like '%".$searchval4."%'");
}

if($field5 == "CITY") {
array_push($clauses, "CITY like '%".$searchval5."%'");
}

$all_clauses = implode(" AND ", $clauses);

$rs = $conn->Execute("SELECT * FROM housenum WHERE ".$all_clauses." ORDER BY ".$sort." ASC");

Jim Dahl, GISP
GIS Coordinator
Douglas County Public Works
526 Willow Dr
PO Box 398
Alexandria MN 56308

V 320-762-2933
   320-762-2999
F 320-762-2998

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geomoose-users/attachments/20120523/9e3573c0/attachment.html


More information about the Geomoose-users mailing list