MultiSearch - orderBY date DESC

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 22, 2016   (RSS)

By Mikey - June 21, 2016

Anyone know how to order the MultiSearch results by date DESC

//SEARCH CODE

$searchOptions = array(); 
$searchOptions['keywords'] = @$FORM['q']; 
$searchOptions['perPage'] = "15"; 
$searchOptions['debugSql'] = "0"; 

$searchTables = array(); 

$searchTables['thome'] = array( 
'viewerUrl' => 'index.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('text'), 
); 

$searchTables['history'] = array( 
'viewerUrl' => 'history.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('title','text'), 
); 

$searchTables['news'] = array( 
'viewerUrl' => 'news.php', 
'titleField' => 'title', 
'summaryField' => 'text', 
'searchFields' => array('title','text'), 
); 

list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);

$searchRow = @$searchRows[0];

Thanks Zick

By Mikey - June 22, 2016

Hey Greg,

Thanks for the help. I made a change to your solution which I wasn't sure would throw errors or not, but it appears to be working like a charm.

What I did is make field1 pull data from a different field - based on that section editor's field need to sort by date DESC, while listing all others by createdDate.

For example I made NEWS 'field1' => 'date', as seen in the bold text within the code below.

//SEARCH CODE
$searchOptions = array(); 
$searchOptions['keywords'] = @$FORM['q']; 
$searchOptions['perPage'] = "15"; 
$searchOptions['debugSql'] = "0"; 
$searchOptions['orderBy']  = "`field1` DESC";

$searchTables = array(); 

$searchTables['thome'] = array( 
  'viewerUrl'    => 'index.php', 
  'titleField'   => 'title', 
  'summaryField' => 'text', 
  'searchFields' => array('text'), 
  'field1'       => 'createdDate',
); 

$searchTables['history'] = array( 
  'viewerUrl'    => 'history.php', 
  'titleField'   => 'title', 
  'summaryField' => 'text', 
  'searchFields' => array('title','text'), 
  'field1'       => 'createdDate',
); 

$searchTables['news'] = array( 
  'viewerUrl'    => 'news.php', 
  'titleField'   => 'title',
  'summaryField' => 'text', 
  'searchFields' => array('title','text'), 
  'field1'       => 'date',
); 

list($searchRows, $searchDetails) = searchMultipleTables($searchTables, $searchOptions);

$searchRow = @$searchRows[0];

Thank you,

Zick