Multi-search with "if" filter on $searchRows

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 2   (RSS)

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

Djulia, the customWhere works beautifully!

Thank you!
Deborah