[ZS2] Re: [mapguide-users] Filter on joined database values

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Wed Jan 14 06:23:37 EST 2009


This is the filter:

$QueryFilter='Drawing+%3D+%26apos%3B74%26apos%3B+AND+Dept+%3D+%26apos%3B136%26apos%3B' 

For some reason the PHP xml system does not seem to autoencode the 
stuff, you must xml encode your input.
I don't know why the above is url encoded though.

The un-encoded filter should look like:
$QueryFilter = 'Drawing = "3B74" AND Dept = "3B136"'

The Xml encoded version should look like this:
$QueryFilter = 'Drawing = "3B74" AND Dept = "3B136"'
No expert on PHP functions, but I found this to help you out:
http://vantol.org/node/31

The $QueryFilter is the string you should change to match your list of 
values.
Build the list like this:

$res = '';

while(odbc_fetch_row($rs))
{
	$bl_id=odbc_result($rs,"bl_id");
	$res .= $bl_id;
	$res .= ',';
}

$res = substr($res, 0, -1); //Remove the last ,
$QueryFilter = xmlencode('ID IN ('.$res.')');


(Note: If the values are not integers, they have to be surrounded with 
quotes).
(Note: You filter column in the SDF may not be called ID).
(Note: xmlencode is the function from the link given)

Regards, Kenneth Skovhede, GEOGRAF A/S

irwan skrev:
>
> Kenneth Skovhede, GEOGRAF A/S wrote:
>   
>> IIRC, something is broken, so you can't filter on a joined database.
>> Instead, you can select keys from the database with an sql like this:
>> select distinct key from table where somecolumn = 'somecriteria';
>>
>> The sql should then give you a list of keys.
>> You can then set the layer filter like this:
>> "ID" IN (...comma seperated key list...)
>> ea: "ID" IN ('1','A')
>>
>> Regards, Kenneth Skovhede, GEOGRAF A/S
>>
>>
>>     
>  i really stucked! really dont have an idea to change Filter element in
> xml.what i want to know here is how to pass a value that i get from sql
> query(php) to xml?i have create a php script, a very simple one to query
> data from database.
>
> $wr_selected="SELECT * FROM wr WHERE bl_id = 'Rev";
>
> $rs=odbc_exec($conn,$wr_selected);
>
>
> while(odbc_fetch_row($rs))
> {
> $bl_id=odbc_result($rs,"bl_id");
> }
>
> currently $bl_id hold a value that satisfy a query. So i want this value put
> into the <Filter></Filter> element in xml file such as <Filter>BL_ID IN
> $bl_id</Filter> but i know this is something we cannot do.
> I look at this code from
>
>   
> $QueryFilter='Drawing+%3D+%26apos%3B74%26apos%3B+AND+Dept+%3D+%26apos%3B136%26apos%3B' 
>    // Load the Query Match Layer Definition template into a PHP DOM object
> and 
>    // modify its Filter node so we're displaying the right building and
> floor. 
>    $doc = DOMDocument::load('QueryMatch.LayerDefinition.xml'); 
>    $FilterNode = $doc->getElementsByTagName('Filter')->item(0); 
>    $FilterNode->nodeValue = $QueryFilter; 
>    $LayerDefinition = $doc->saveXML(); 
>    $byteSource = new MgByteSource($LayerDefinition,   
> strlen($LayerDefinition)); 
>    $byteSource->SetMimeType(MgMimeType::Xml); 
>    $tempResourceID = new
> MgResourceIdentifier("Library://HumboldtFM/Layers/QueryMatch.LayerDefinition"); 
>    $resourceService->SetResource($tempResourceID, $byteSource->GetReader(),
> null); 
>
> but i really dont know that to do with this code. Can someone here assist
> me?
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090114/5f7066a8/attachment.html


More information about the mapguide-users mailing list