[mapserver-users] Filter query

Steven Bowden steveb at bundaberg.qld.gov.au
Tue Jul 23 02:47:27 EDT 2002


Hello all,
I am having trouble figuring out how to use filters in php/mapscript
3.6.1.
I have a layer where I want to dynamically change the filter string.
Here is the layer out of the map file
LAYER
  NAME selected_parcel
  GROUP cadaster
  CONNECTIONTYPE postgis
  CONNECTION "user=steveb dbname=blis host=blis"
  TYPE polygon
  STATUS off
  TEMPLATE ""
  #FILTER "tag = 'RP83015/1'"  # Option 1
  FILTER "tag = 'test_string'"      # Option 2
  TRANSPARENCY 50
  DATA "the_geom from bucc"
  CLASS
     Name "Selected Parcel"
     COLOR 255 220 220
  END
END

Here is the relevant mapscript stuff
$rp=RP83015/1;
$selected_layer = $map->getlayerbyname(selected_parcel);
$selected_layer->setfilter("tag = $rp");
$selected_layer->set(status,MS_ON);
$image=$map->draw();
$image_url=$image->saveWebImage(MS_PNG,1,1,0);

I keep getting the following error and no image when I try and run the
script:
Warning: MapServer Error in msPOSTGISLayerWhichShapes(): prep_DB:Error
executing POSTGIS DECLARE statement (0.6 failed - retried 0.5 and it
failed too). DECLARE mycursor BINARY CURSOR FOR SELECT
tag::text,asbinary(force_collection(force_2d(the_geom)),'NDR'),OID::text
from bucc WHERE (tag = RP83015/1) and (the_geom && setSRID(
'BOX3D(432838.932823529 7247483.128,432988.617176471
7247568.006)'::BOX3D,find_srid('','bucc','the_geom') )) in
/var/www/html/blis_dev/lis.phpm on line 86

I suspect it is due to the where clause in the sql, ie WHERE (tag =
RP83015/1).  I have tried placing the single quotes (') around $rp in
the setfilter line and it still fails.  The where clause in the error
message looks like this, WHERE (tag = ).  I have tried escaping the
single quotes with backslashes but still no go.
Is there another way to escape the single quotes so that they appear in
the where clause as 
WHERE (tag = 'RP83015/1')  ?
If not, am I going about this process in the correct way?
When I comment out the setfilter line in php and change the comment
around on Option 1 & 2 in the map file everything works how I want it
to.

Any advice would be greatly appreciated.
Thanks
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20020723/65e7defb/attachment.html


More information about the mapserver-users mailing list