brainonastick Posted July 6, 2006 Posted July 6, 2006 Hi there, I have built a search form which allows browsers to search for courses using any of the following fields: Course Name Starting Date Presenter Venue Stream I know that PHP searches default to "AND" and only records containing all criteria will be found unless otherwise specified. I also know that you can add a line of code to change the search to an "OR" search as follows: $InstanceName->AddDBParam('-lop', 'or'); But what I want is for the browser (person) to be able to select AND or OR in a drop-down list in the online search form so that the PHP script processes the search request based on their choice. So I need some kind of IF statement in the PHP code. Does anyone know how to code this? All replies received with thanks. Steven
Martin Brändle Posted July 9, 2006 Posted July 9, 2006 Do you want to mix AND and OR in the same query or just offer the possibility to either do AND or do OR queries? The first is not possible solely with one query to the WPE (it does not allow mixing of OR/AND). This is an old restraint since the FileMaker CDML days, which still has not been resolved by FMI. You would have to send separate queries to the WPE, and then combine the results later with PHP or XSLT (Apache Xalan, the XSLT processor used by FMSA, offers set extension functions like difference or intersection for acting on XML result tree fragments). For the latter, there should be a PHP solution (unfortunately, I don't know FX.php , but there will be an expert of this forum around who can answer this question, .e.g. Stephen Knight from FMWebSchool).
andygaunt Posted July 9, 2006 Posted July 9, 2006 I will jump in for Martin on the PHP and the second option he states. If you just want the user to be able to choose AND/OR you can simply write your IF statement into your PHP query. $operator = $_POST['operator'] //This is the name of your and/or choice field in the form $query = new FX($serverIP,$webCompanionPort); $query -> SetDBData('databaseName','layout','groupSize'); $query -> SetDBPassword('password,'username'); //Your if check can now go here to see if the OR choice was made. If AND was chosen no problems if ($operator == "OR") { $query -> AddDBParam('-lop', 'or'); } $query -> AddDBParam('fieldName','formValuesHere'); //Add all your search fields here $queryResult = $query->FMFind(); //Rest of page goes here
brainonastick Posted July 9, 2006 Author Posted July 9, 2006 Thanks andygaunt for your reply. That's exactly what I needed. Thanks also Martin for the heads up on AND/OR but my browsers will choose one or the other when they do a search.
Recommended Posts
This topic is 6781 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now