Multi-search with "if" filter on $searchRows
3 posts by 2 authors in: Forums > CMS Builder
Last Post: about an hour ago (RSS)
In my multi-search page results, I want to omit listings that aren't approved via the "approved" checkbox.
I followed Damon's idea in the following post, but it's either not working, or I've got something not right.
https://interactivetools.com/forum/forum-posts.php?postNum=2236421#post2236421
// list of businesses
list($business_directoryRecords, $business_directoryMetaData) = getRecords(array(
'tableName' => 'business_directory',
'loadCreatedBy' => false,
));
// SEARCH BY WORD/PHRASE //
// for type-in search box
$searchOptions = array();
$searchOptions['keywords'] = @$_REQUEST['q'];
$searchOptions['perPage'] = "200";
$searchOptions['debugSql'] = "0" ; // set to '1' to use debug
$searchTables = array();
$searchTables['business_directory'] = array(
'viewerUrl' => '/business/directory/directory-search-results.php',
'titleField' => 'business_name',
'summaryField' => 'description',
'field1' => 'num' ,
'field2' => 'contact_names',
'field3' => 'phone_1',
'field4' => 'phone_2',
'field5' => 'address',
'field6' => 'town_city',
'field7' => 'business_website_url',
'field8' => 'alternate_website_url',
'field9' => 'alternate_website_url_title',
'field10' => 'approved',
'searchFields' => array('business_name','description','contact_names'),
);
list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);
<!-- HTML Search Results List -->
<?php $count = 0;?>
<?php foreach ($searchRows as $record): ?>
<?php if($record['field10'] == 1) { continue; } ?>
<!-- ShowMe simplified results -->
Array
(
[tablename] => business_directory
[num] => 3
[field10] => 0
)
Note the [field10] shows a value of 0, but that record displays anyhow.
Does anyone have any thoughts on this? If it can't be done, then we won't be able to use multi-search.
Thanks for any help in advance!
~ Deborah
Hi Deborah,
Since you're using an "approved" checkbox field, you can simply exclude unapproved listings with:
customWhere: "approved = '1'"
// list of businesses
list($business_directoryRecords, $business_directoryMetaData) = getRecords(array(
'tableName' => 'business_directory',
'loadCreatedBy' => false,
));
// SEARCH BY WORD/PHRASE //
// for type-in search box
$searchOptions = array();
$searchOptions['keywords'] = @$_REQUEST['q'];
$searchOptions['perPage'] = "200";
$searchOptions['debugSql'] = "0"; // set to '1' to use debug
$searchTables = array();
$searchTables['business_directory'] = array(
'viewerUrl' => '/business/directory/directory-search-results.php',
'titleField' => 'business_name',
'summaryField' => 'description',
'field1' => 'num',
'field2' => 'contact_names',
'field3' => 'phone_1',
'field4' => 'phone_2',
'field5' => 'address',
'field6' => 'town_city',
'field7' => 'business_website_url',
'field8' => 'alternate_website_url',
'field9' => 'alternate_website_url_title',
'field10' => 'approved',
'searchFields' => array(
'business_name',
'description',
'contact_names'
),
// ONLY show approved listings
'customWhere' => "approved = '1'",
);
list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);
This ensures that only listings with the approved checkbox checked are included in your multi-search results.
I hope this helps!
Djulia