<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/1.0.2">
</HEAD>
<BODY>
Hello all,
<BR>
I am having trouble figuring out how to use filters in php/mapscript 3.6.1.
<BR>
I have a layer where I want to dynamically change the filter string.
<BR>
Here is the layer out of the map file
<BR>
LAYER
<BR>
NAME selected_parcel
<BR>
GROUP cadaster
<BR>
CONNECTIONTYPE postgis
<BR>
CONNECTION "user=steveb dbname=blis host=blis"
<BR>
TYPE polygon
<BR>
STATUS off
<BR>
TEMPLATE ""
<BR>
#FILTER "tag = 'RP83015/1'" # Option 1
<BR>
FILTER "tag = 'test_string'" # Option 2
<BR>
TRANSPARENCY 50
<BR>
DATA "the_geom from bucc"
<BR>
CLASS
<BR>
Name "Selected Parcel"
<BR>
COLOR 255 220 220
<BR>
END
<BR>
END
<BR>
<BR>
Here is the relevant mapscript stuff
<BR>
$rp=RP83015/1;
<BR>
$selected_layer = $map->getlayerbyname(selected_parcel);
<BR>
$selected_layer->setfilter("tag = $rp");
<BR>
$selected_layer->set(status,MS_ON);
<BR>
$image=$map->draw();
<BR>
$image_url=$image->saveWebImage(MS_PNG,1,1,0);
<BR>
<BR>
I keep getting the following error and no image when I try and run the script:
<BR>
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
<BR>
<BR>
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.
<BR>
Is there another way to escape the single quotes so that they appear in the where clause as
<BR>
WHERE (tag = 'RP83015/1') ?
<BR>
If not, am I going about this process in the correct way?
<BR>
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.
<BR>
<BR>
Any advice would be greatly appreciated.
<BR>
Thanks
<BR>
Steve
</BODY>
</HTML>