[Geomoose-users] Need help with ELSE / OR statements

Jim Dahl jim.dahl at mail.co.douglas.mn.us
Fri Aug 20 10:59:40 EDT 2010


I tried it so here is the file.  I  tweaked it a bit removed extra
dollar sign, curly bracket, and double quotes but still not working.  I
will continue to look at it.
 
jim
 
<html>
<head>
</head>
<?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.
$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");
  } else {
    echo "You have reached this page by mistake.";
  }

}
?>
<body>
 
<b>Search Results:</b>
      <?php
      // Display all the values in the records set
      if ($field <> "none") {
        if ($rs->EOF) {
         echo "<br><b>Search Found No Records!</b><br>";
        } else {
      echo "<table border='0' width='250' class='message'>";
      while (!$rs->EOF) {
        $fv1 = $rs->Fields("TRS");
        $fv2 = $rs->Fields("SECTION");
        $fv3 = $rs->Fields("TOWNSHIP");
        $fv4 = $rs->Fields("RANGE");
        $fv5 = $rs->Fields("LOCATION");
        $fv6 = $rs->Fields("DOCTYPE");
        $fv7 = $rs->Fields("DOCUMENTID");
        $fv8 = $rs->Fields("CREATOR");
        $fv9 = $rs->Fields("DATE");
        $fv10 = $rs->Fields("DESCRIPTION");
        $fv11 = $rs->Fields("NUMOBJECTS");
        $fv12 = $rs->Fields("PAGENUM");
        $fv13 = $rs->Fields("QUICKLINK");
        $fv14 = $rs->Fields("OBJECTID");
        $fv15 = $rs->Fields("TRS_ORIG");
        echo "<tr>";
//        echo '<td>TRS#: <a
href=\'../survey_section_mi_parcelform.php?str='.$fv1->value.'\'
title=\'Click to View Survey Info\'
target=\'_blank\'>'.$fv1->value.'</a>&nbsp;';
 
        echo '<td>TRS#: <a href=\'../pdf/'.$fv13->value.'\'
title=\'Click to View Survey Scanned Image\'
target=\'_blank\'>'.$fv1->value.'</a>&nbsp;';
 
        echo '<a
href=\'javascript:getMapbook("php/zoomto.php?map=/ms4w/apps/GeoMOOSE/dou
glas/maps_douglas/sections/itemquery_sections.map&mode=xml&highlight=tru
e&buffer=500&qitem=STRING&qstring='.$fv15->value.'", Events, Map,
true)\'><img src=\'shared/images/view.png\' border=\'0\' title=\'Click
to Zoom Map to Parcel\'></a><br>';
        echo "Section: ".$fv2->value."<br>";
             echo "Township: ".$fv3->value."<br>";
             echo "Range: ".$fv4->value."<br>";
             echo "Location: ".$fv5->value."<br>";
        echo "Document Type: ".$fv6->value."<br>";
        echo "Document ID: ".$fv7->value."<br>";
             echo "Creator: ".$fv8->value."<br>";
             echo "Date: ".$fv9->value."<br>";
             echo "Description: ".$fv10->value."<br>";
             echo "Number of Pages: ".$fv11->value."<br>";
             echo "Page Number: ".$fv12->value."<br>";
             echo "Object ID: ".$fv14->value."<br>";
        //echo "<td><a href=\"javascript:alert(Function not implemented:
PIN ".$fv1->value.")'><img src='icons/zoomtofeature.png' border='0'
title='Click to Zoom Map to Parcel'></a></td>";
        echo "</tr>";
        echo "<tr><td><hr></td></tr>";
        $rs->MoveNext();
      }
      echo "</table>";
    }
   }
   ?>
 
</body>
<?php
if ($field <> "none") {
 $rs->Close();
 $conn->Close();
 $rs = null;
$conn = null;
} //end if statment
?>
</html>

	-----Original Message-----
	From: Dan Little [mailto:danlittle at yahoo.com] 
	Sent: Thursday, August 19, 2010 5:54 PM
	To: Jim Dahl; geomoose-users at lists.sourceforge.net
	Subject: Re: [Geomoose-users] Need help with ELSE / OR
statements
	
	
	Is this the old version of the script? It looks like it does not
include the code suggestion I made.


		From: Jim Dahl <jim.dahl at mail.co.douglas.mn.us>
		To: Dan Little <danlittle at yahoo.com>;
geomoose-users at lists.sourceforge.net
		Sent: Thu, August 19, 2010 3:02:23 PM
		Subject: RE: [Geomoose-users] Need help with ELSE / OR
statements
		
		
		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/20100820/7c89f39e/attachment.html


More information about the Geomoose-users mailing list