[mapserver-users] queryByAttribute()

kenboss kenboss at dilbert.dnr.state.mn.us
Mon Apr 29 11:23:17 EDT 2002


I do these things in Perl, but I think for the most part the PHP setup parallels the Perl setup.  That 
said, it looks to me like the PHP docs are missing a ResultCacheObj Class, which belongs to a layer and 
holds the results of a query on that layer.  

Also note that queryByAttributes (or any of the queryBy methods for that matter) returns success or 
failure, not an index variable.  

So generally, in Perl, you might say something like:

$return_value = $thislayer->queryByAttributes($map, $mapscript::MS_MULTIPLE);
if ($return_value == $mapscript::MS_SUCCESS) {
  for ($i=0; $i<$thislayer->{resultcache}->{numresults); $i++) {
  # resultcache is member of layer, numresults is member of resultcache
    $result = $thislayer->getResult($i);
    $rv = $thislayer->getShape($shape, $result->{tileindex}, $result->{shapeindex});
    # Now do something with the shape...
  }
} else {
  warn "Nothing Found.";
}

Hope this helps,

--Ken Boss

> > then get your results like:
> >
> > for ($i=0; $i<$layer->{resultcache}->{numresults}; $i++) {
> >     $result = $layer->getResult($i);
> >     ... (do something with the result)
> > }
> 
> OK, I been lurking on this question, nd I really want to know some of the secrets too. I got as far as
> getting the result as indicated below (although I am using PHP mapscript), but it is the "do something
> with result" part which has me stumped. I can not get any action out of any of the variables listed in
> the php mapscript documentation for result, and trying to fetch each of the results by using
> $thisresult->next() gives me an "Fatal error:  Call to undefined function:  next()" error.
> 
> basically, I am trying to iterate through each shape in a given layer, and do such things as query for
> adjacent neighbors, in the fashion of a neighborhood function. Any help would be appreciated. By the 
way,
> my query .numresult gives me the number of shapes int eh layer, which makes me think things are going 
OK
> till then. Code is as follows:
> 
> $lq = $thislayer->queryByAttributes(MS_MULTIPLE);
>           $ni = $thislayer->getNumResults();
>           $res = $thislayer->getResult($lq);
>           $rsi = $res->numresults;
>           $rti = $res->numquerylayers;
>           $restr = $res->next();






More information about the mapserver-users mailing list