mlindal Posted December 19, 2005 Posted December 19, 2005 I have a difficult search (the search from hell). The form has several fields, so we need to use LOP=AND in order to find all records. Next, I have one field 'PubLanguageID' that I need to do a LOP=OR. The idea being that if a person is wanting to search for all the English publications they could be found in the set: {PL1 = English, PL2 = English / French, etc}, the field only contains codes so that we can change the context of the web pages between french and English. Here is the search query: $search=new FX($serverIP,$webCompanionPort); $search->SetDBData('Pub_Publication_.fp5','ForPHP', $groupSize); $search->AddDBParam('Bookstore_Detail_Flag','Yes'); $search->AddDBParam('TitleSubAlt',$TitleSubAlt); $search->AddDBParam('PersonalNameList',$PersonalNameList); $search->AddDBParam('YearOfPublication',$YearOfPublication); $search->AddDBParam('ISBN',$ISBN); $search->AddDBParam('Web_SeriesVolume',$Series); $search->AddDBParam('Keywords',$Keywords); if($Language=='English'); { $search->AddDBParam("PubLanguageID","PL1"); $search->AddDBParam("PubLanguageID","PL2"); $search->AddDBParam("PubLanguageID","PL12"); $search->AddDBParam("PubLanguageID","PL19"); $search->AddDBParam("PubLanguageID","PL11"); $search->AddDBParam("PubLanguageID","PL4"); } if($Language=='French'); { $search->AddDBParam("PubLanguageID","PL2"); $search->AddDBParam("PubLanguageID","PL12"); $search->AddDBParam("PubLanguageID","PL3"); $search->AddDBParam("PubLanguageID","PL4"); $search->AddDBParam("PubLanguageID","PL9"); } if($Language=='English / French'); { $search->AddDBParam("PubLanguageID","PL2"); } if($Language=='English / French'); { $search->AddDBParam("PubLanguageID","PL2"); $search->AddDBParam("PubLanguageID","PL4"); } if($Language=='Spanish'); { $search->AddDBParam("PubLanguageID","PL9"); $search->AddDBParam("PubLanguageID","PL5"); } if($Language=='Russian'); { $search->AddDBParam("PubLanguageID","PL10"); $search->AddDBParam("PubLanguageID","PL11"); $search->AddDBParam("PubLanguageID","PL12"); } if($Language=='Italian'); { $search->AddDBParam("PubLanguageID","PL6"); } if($Language=='German'); { $search->AddDBParam("PubLanguageID","PL7"); } if($Language=='Other'); { $search->AddDBParam("PubLanguageID","PL8"); } $search->AddDBParam('-op','cn'); $search->FMSkipRecords($skipSize); $search->AddSortParam('YearOfPublication','descend'); $search->AddSortParam('CatalogNumber','descend'); $searchResult=$search->FMFind();
Garry Claridge Posted December 20, 2005 Posted December 20, 2005 About the only way is to refine/filter, in PHP, the returned records from the "AND" search. You can use the "in_array()" function. Maybe something like this: switch ($Language) { case "English": $lang_array = array("PL1","PL2","PL12","PL19","PL11","PL4"); break; case "French": $lang_array = array(..... ... }; foreach($searchResult['data']as $key=>$searchData); if(in_array($searchData['PubLanguage'][0], $lang_array)) { do something.... } Hope this works for you. All the best. Garry
mlindal Posted December 20, 2005 Author Posted December 20, 2005 ok, That makes sense... Sometimes the long way and brute force is the only way to get there. thanks.
mlindal Posted December 20, 2005 Author Posted December 20, 2005 Gary, all that you have said is good... is there a simple way to get a found count? IE) Your search has found 51 publications: Pub 1 title... Pub 2 title etc Logic is $searchResult['foundCount'] is for the entire found set, but then we use in_array() to get a subset, so we can't use 'foundCount' hmmm using a counter $i ++ might work, but then won't be able to display it until the end of the found records,
Garry Claridge Posted December 20, 2005 Posted December 20, 2005 As a quick thought! Use some Javascript to write the FoundCount back at the top of the document. Good Luck. Garry
mlindal Posted December 20, 2005 Author Posted December 20, 2005 Got the found count using PHP: $totalpubs=0; $i=0; foreach($searchResult['data'] as $key=>$keyData){ if(in_array($keyData['PubLanguageID'][0], $lang_array)) { $subData[$i]=$searchData; $i=$i+1; } $totalpubs=$i; } Note: you can see I am attempting to take the subset of publications and put it into a new array because... in my main html code: <? foreach($searchResult['data'] as $key=>$searchData){ if(in_array($searchData['PubLanguageID'][0], $lang_array)) { ?> Publication title: <? echo $searchData['title'];?> <?} }?> what this does is only show the found pubs, but if I have an original found count of 120 publications and want to display 10 at a time, it will show blanks and maybe 1 or 2, then buttons. So what I would like to do is getting my coding straight so that only the pubs show and no blanks. My thought is to get the new subset into a new array and then parse that, but I have having difficulty tracking how and where the data goes.
Garry Claridge Posted December 21, 2005 Posted December 21, 2005 Generally the style I use for scripted pages is to separate the Logic and the Presentation. I do this by building "display blocks" in the Logic section, then in the Presentation section I "echo/print" these blocks. In practical terms most of the PHP is at the top of the page and most of the HTML is at the bottom of the page with some PHP to print the "display blocks; e.g. <?=$display_block1?> In relation to biulding a result array; I believe this is the way to go. You will have to refine the methods used to smooth-up the process. All the best. Garry
Recommended Posts
This topic is 6982 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