[Geomoose-users] Need help with ELSE / OR statements
Jim Dahl
jim.dahl at mail.co.douglas.mn.us
Thu Aug 19 16:02:23 EDT 2010
Dan, it must be getting close. I had to take out a curly bracket } and
a dollar sign $ to make it not error out but search came back empty. I
will include more script if that helps.
<?php
$field=(isset($_REQUEST['field']))?$_REQUEST['field']:"none";
$field2=(isset($_REQUEST['field2']))?$_REQUEST['field2']:"none";
$sort=(isset($_REQUEST['sort']))?$_REQUEST['sort']:"Surveyor_Image_Link.
TRS";
//$sort2=(isset($_REQUEST['sort2']))?$_REQUEST['sort2']:"Surveyor_Image_
Link.DOCTYPE";
$searchval=(isset($_REQUEST['searchval']))?$_REQUEST['searchval']:"none"
;
$searchval2=(isset($_REQUEST['searchval2']))?$_REQUEST['searchval2']:"no
ne";
if ($field <> "none") {
// Microsoft Access connection string.
// Douglas server
//$db =
'\\ms4w\\apps\\GeoMOOSE\\douglas\\maps_douglas\\database\\parcels.mdb';
// HEI server
$db =
'\\ms4w\\apps\\GeoMOOSE\\douglas\\maps_douglas\\database\\aex.mdb';
$conn = new COM('ADODB.Connection'); // or exit('Cannot start ADO.');
// Two ways to connect. Choose one.
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db"); //
or exit('Cannot open with Jet.');
//$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db"); //
or exit('Cannot open with driver.');
// SQL statement to build recordset.
if ($field == "TRS" || $field2 == "DOCTYPE") {
$rs = $conn->Execute("SELECT * FROM Surveyor_Image_Link WHERE TRS
LIKE '%".$searchval."%' ORDER BY ".$sort." ASC");
// ||
// ) elseif ($field2 == "DOCTYPE") {
// $rs = $conn->Execute("SELECT * FROM Surveyor_Image_Link WHERE
DOCTYPE LIKE '".$searchval2."%' ORDER BY ".$sort." ASC");
} else {
echo "You have reached this page by mistake.";
}
}
?>
-----Original Message-----
From: Dan Little [mailto:danlittle at yahoo.com]
Sent: Thursday, August 19, 2010 1:05 PM
To: Jim Dahl; geomoose-users at lists.sourceforge.net
Subject: Re: [Geomoose-users] Need help with ELSE / OR
statements
Good news, GM2.2 can do this! :) Bad news... GM1.6 is harder and
you need to use manual SQL.
$clauses = array();
if($field == "TRS") {
array_push($clauses, "TRS like '%".$searchval$."%'");
}
if($field2 == "DOCTYPE") {
array_push($clauses, "DOCTYPE LIKE '".$searchval2."%'");
}
$all_clauses = implode(" or ", $clauses);
$rs = $conn->Execute("SELECT * FROM Surveyor_Image_Link WHERE
".$all_clauses." ORDER BY ".$sort." ASC");
From: Jim Dahl <jim.dahl at mail.co.douglas.mn.us>
To: geomoose-users at lists.sourceforge.net
Sent: Thu, August 19, 2010 9:56:08 AM
Subject: [Geomoose-users] Need help with ELSE / OR
statements
I am trying to add two search fields in my GM app. I
can make each field search correctly by themselves but not together. I
have the code where the first two lines work and when I comment out the
first two and enable the second two lines, the code works for
searchval2. What I want to know is how can I use ELSE with or without
the OR statements to allow me to enable both fields for the search?
if ($field == "TRS") {
$rs = $conn->Execute("SELECT * FROM
Surveyor_Image_Link WHERE TRS LIKE '%".$searchval."%' ORDER BY ".$sort."
ASC");
// ) if ($field2 == "DOCTYPE") {
// $rs = $conn->Execute("SELECT * FROM
Surveyor_Image_Link WHERE DOCTYPE LIKE '".$searchval2."%' ORDER BY
".$sort." ASC");
} else {
echo "You have reached this page by mistake.";
}
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/20100819/c30c575a/attachment.html
More information about the Geomoose-users
mailing list