[mapguide-users] query code help...

Paul Spencer pagameba at gmail.com
Wed Jan 23 06:42:41 EST 2008


Not sure what you are looking for here, but you need to call  
$queryOptions->SetFilter() with a string that looks like an SQL  
statement ... something like:

$queryOptions->SetFilter('(FIELD = "apple") AND (STATE = "state1") AND  
(AREA >= 1000)');

If you have multiple possible inputs coming from the client, my  
favourite way to do this is as follows:

$opts = array();
if (isset($_REQUEST['FIELD'])) {
     array_push($opts, 'FIELD = "'.$_REQUEST['FIELD'].'"');
}
if (isset($_REQUEST['STATE'])) {
     array_push($opts, 'STATE = "'.$_REQUEST['STATE'].'"');
}
if (isset($_REQUEST['AREA'])) {
     array_push($opts, 'AREA >= '.$_REQUEST['AREA']);
}
if (count($opts)) {
     $queryOptions->SetFilter('('.implode(') AND (', $opts).')');
}

Note that this assumes you know the fields you want to query and there  
type so you can quote them correctly.  A more generic solution is  
obviously possible but requires a lot more code.

Cheers

Paul

On 23-Jan-08, at 1:47 AM, lolob wrote:

>
> hi,
> I need help with the code here..I want to create query that can use 3
> property...for example...i want to filter something like this "FIELD  
> = apple
> and STATE = state1 and AREA >= 1000 "...the question is how do I  
> combine the
> statement and send to $propertyFilter...and how to add the logic 'AND'
> statement here...
>
> thanks..
>
>> From sample version
> $queryOptions = new MgFeatureQueryOptions();
>
> if ($this->args['USEPROPERTYFILTER'] == 'true')
> {
>   $propertyFilter = $this->args['PROPERTYNAME'];
>
>   if ($this->args['ISSTRING'] == 'true')
> 	$propertyFilter .= sprintf($this->strExpressions[$this- 
> >args['OPERATOR']],
> $this->args['VALUE']);
>   else
> 	$propertyFilter .= sprintf($this->numExpressions[$this- 
> >args['OPERATOR']],
> $this->args['VALUE']);
>
>  $queryOptions->SetFilter($propertyFilter);
> }
>
>
> my version
> if ($this->args['USEPROPERTYFILTER'] == 'true')
> {
>   $propertyFilter1 = $this->args['PROPERTYNAME'];
>   if ($this->args['ISSTRING'] == 'true')
> 	$propertyFilter1 .=
> sprintf($this->strExpressions[$this->args['OPERATOR1']],
> $this->args['VALUE1']);
>   else
> 	$propertyFilter1 .=
> sprintf($this->numExpressions[$this->args['OPERATOR1']],
> $this->args['VALUE1']);
>
>   $propertyFilter2 = $this->args['PROPERTYNAME'];
>   if ($this->args['ISSTRING'] == 'true')
> 	$propertyFilter2 .=
> sprintf($this->strExpressions[$this->args['OPERATOR2']],
> $this->args['VALUE2']);
>   else
> 	$propertyFilter2 .=
> sprintf($this->numExpressions[$this->args['OPERATOR2']],
> $this->args['VALUE2']);
>
>   $propertyFilter3 = $this->args['PROPERTYNAME3'];
>   if ($this->args['ISSTRING'] == 'true')
> 	$propertyFilter3 .=
> sprintf($this->strExpressions[$this->args['OPERATOR3']],
> $this->args['VALUE3']);
>   else
> 	$propertyFilter3 .=
> sprintf($this->numExpressions[$this->args['OPERATOR3']],
> $this->args['VALUE3']);
>
>
>
> $queryOptions- 
> >SetFilter($propertyFilter1.$propertyFilter2.$propertyFilter3);
> }
> -- 
> View this message in context: http://www.nabble.com/query-code-help...-tp15035839s16610p15035839.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users



More information about the mapguide-users mailing list