MultiSearch - orderBY date DESC

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

By gregThomas - June 21, 2016

Hey Zick, 

Something like this should work:

//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'       => 'createdDate',
); 

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

$searchRow = @$searchRows[0];

The multi search system allows you to set the contents of a field from a particular section to variables with names field1 - field10.

So for each section that get's searched I'm setting the createdDate of the records to the custom field field1. Then I've added an orderBy statement to the options that will sort by field1. You can use a different date field for each section if required.

Let me know if you have any questions. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

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