[FX.php List] Mixed search requests

Erik Andreas Cayré erik at cayre.dk
Wed Oct 25 15:58:22 MDT 2006


Den 25/10/2006 kl. 21.28 skrev Chris Bisgard:

> Hello all,
>
> This question may reveal my inexperience with FileMaker queries and
> scripts, PHP, or databases in general, but here goes... I have a
> contacts database of arts organizations, and I want to be able to do a
> logical "OR" keyword search of three different fields (organization
> name, description, and category), and then optionally narrow the  
> results
> by one of three geographic locales AND optionally by one of seven
> artistic disciplines (exact matches). Because of FileMaker's inability
> to combine logical AND/OR search types, I am currently doing this by
> doing the initial keyword search, and then running scripts on the  
> found
> set to constrain first by locale and then by discipline. The AddParam
> statements for which scripts to run are determined conditionally based
> on POST data. Also, if keyword is left blank, it just does a Find All
> and then runs the scripts on that.
>
> This works fine for the first script (constrain by location), but not
> for the second (constraing by discipline). For some reason, the second
> script doesn't seem to be running after the first one? I'm not really
> sure what's happening. In any case, the results are that I get a
> successful keyword search that is then successfully constrained to the
> selected locale, but not constrained again by discipline.

Sounds like FMSA/FX only supports running one script as part of a query.

> My question is, can I use a second instance of FX to query the SAME
> results for discipline, based on whether the user has included that in
> their criteria?

You might...! FMSA supports 'sessions' in XML queries (I think they  
are an option using FMI's PHP API), but I don't think FX.php supports  
this.
Correct me, anyone?
BTW. I'm referring to database sessions, *not* PHP sessions...!

> Or is it better to just have a PHP script that walks
> through the results array and pulls out records containing the  
> requested
> discipline?

Yes, better.

> My concern with that is that it will mess up my found count,
> next/prev links, etc., unless I write some fancy code to deal with  
> those
> items... And I'm not sure if I know how to do that with an array,  
> in any
> case.

Fancy code: walk the array you get from FX using foreach.
In the foreach you copy just the records you need into another array  
using whatever filtering is necessary.
Use the new array for display and base your prev/next links on that.
You'll have to store this array in a $_SESSION for your prev/next to  
work as expected.
This will save some time looking in FM (just one search per session)  
and cost you some time with the larger array stored in the $_SESSION.
I think you're ok, if your dataset isn't huge, and the data doesn't  
change very often.

> Optionally, is it possible to pass user variables from PHP to a script
> in FileMaker, so that I could do both constrains dynamically in one
> script, based on user input? Or am I just making this harder than it
> needs to be?

I'm not aware of a direct way for FX to pass script parameters. I  
have an (untried) idea though:
Put the parameters into global fields with an FMedit first. Then do  
your FMfind calling one master script which uses the contents of the  
global fields...?

If you try this approach, let us know what happens...

> I hope this all makes sense... I'm tired and my vision is blurry.  
> Below
> is the code for the "search/script/script" model described in my first
> paragraph.
>
> And a big thanks to anyone who reads this and has any ideas.
>
> Chris Bisgard
> Information Technology Specialist
> Regional Arts & Culture Council
> 108 NW 9th Avenue, Suite 300
> Portland, Oregon 97209-3318
> cbisgard at racc.org
>
> ------ CODE HERE ------
>
> include_once("/inetpub/wwwroot/FX/FX.php");
> include_once("/inetpub/wwwroot/FX/server_data.php");
> include_once("/inetpub/wwwroot/FX/FMErrors.php");
>
> $search=new FX($serverIP,$webCompanionPort);
> $search->setDBData('ArtResources','web',$returnCount);
> $search->AddDBParam('-lop','or');
>
> if ($_POST['keyword'] != "") {
> 	$keyword = $_POST['keyword'];
> 	$search->AddDBParam('OrgName',$keyword,$op='cn');
> 	$search->AddDBParam('Description',$keyword,$op='cn');
> 	$search->AddDBParam('Category',$keyword,$op='cn');
> 	$search->AddDBParam('Discipline',$keyword,$op='cn');
> }
>
> // If the "Locale" option is set, run the appropriate script in
> FileMaker to constrain results by locale
> if ($_POST['geo'] != "") {
> 	$geo = $_POST['geo'];
> 	if ($geo == "Portland Metro") {
> 		$search->AddDBParam('-script.presort','Geo_PDXMetro');
> 	}
> 	elseif ($geo == "Oregon/Washington") {
> 		$search->AddDBParam('-script.presort','Geo_OrWash');
> 	}
> 	elseif ($geo == "National/International") {
> 		$search->AddDBParam('-script.presort','Geo_NatlIntl');
> 	}
> }
>
> // If the "Discipline" option is set, run the appropriate script in
> FileMaker to constrain results by discipline
> if ($_POST['discipline'] != "") {
> 	$discipline = $_POST['discipline'];
> 	if ($discipline == "Dance") {
> 		$search->AddDBParam('-script.presort','Dsp_Dance');
> 	}
> 	elseif ($discipline == "Film/Video/Media Arts") {
> 	
> $search->AddDBParam('-script.presort','Dsp_FilmVideoMedia');
> 	}
> 	elseif ($discipline == "Literary Arts") {
> 		$search->AddDBParam('-script.presort','Dsp_Literary');
> 	}
> 	elseif ($discipline == "Music") {
> 		$search->AddDBParam('-script.presort','Dsp_Music');
> 	}
> 	elseif ($discipline == "Theater") {
> 		$search->AddDBParam('-script.presort','Dsp_Theater');
> 	}
> 	elseif ($discipline == "Visual Arts") {
> 		$search->AddDBParam('-script.presort','Dsp_Visual');
> 	}
> 	elseif ($discipline == "Other") {
> 		$search->AddDBParam('-script.presort','Dsp_Other');
> 	}
> }
>
> // Decide whether to search by keyword or just find all records
> if ($keyword != "") {
> 	$searchResult=$search->FMFind();	
> }
> else {
> // Since no keyword present, find ALL records
> 	$searchResult=$search->FMFindAll();		
> }
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list



---
Erik Andreas Cayré
Spangsbjerg Møllevej 169
DK-6705 Esbjerg Ø

Home Tel: +45 75150512
Mobile: +45 40161183

»If you can't explain it simply, you don't understand it well enough.«
-- Albert Einstein

»If you don't have time to do it right, when will you have time to do  
it over?«
-- John Wooden, basketball coach


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1856 bytes
Desc: not available
Url : http://www.iviking.org/pipermail/fx.php_list/attachments/20061025/3419c1e6/smime.bin


More information about the FX.php_List mailing list