MultiSearch.php

By Toledoh - August 7, 2016

Hey Guys.

I've currently got search results linking to the "detail" page for a table.

$searchTables['table'] = array(
'viewerUrl' => 'detail.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content','details'),
);

However, some of these records do not have any content.  On the list page, I only show a link to the detail page where they have "content" ie.

<?php if ($record['content']): ?>
<a href="<?php echo $record['_link'] ?>"></a>
<?php endif ?>

Is it possible to have a similar thing in MultiSearch.php, where if there's content, have the 'viewerUrl' => 'detail.php', but if there's no content, have 'viewerUrl' => 'list.php'

Cheers,

Tim (toledoh.com.au)

By Damon - August 8, 2016

Hi Tim,

Here is some code that will take the user to a detail page if there is content or else if not content, send them to an alternate link:

<?php if ($record['_summary']): ?>
  <a href="<?php echo $record['_link'] ?>" style="color: #008000"><?php echo $record['_link'] ?></a><br/><br/>
<?php else : ?>
  <a href="alternate_link.php" style="color: #008000">ALTERNATE LINK</a><br/><br/>
<?php endif ?>

Also, inside the foreach loop for the search results, you can add this code to see all the data and variable names you are working with:

<?php showme($record); ?>

This helps with setup and testing. Let me know if you have any questions or need anything else.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Toledoh - August 8, 2016

Thanks Damon,

However this will not work for me because every table is different, and therefore has a different alternate link.

I think I need something that will allow me to prescribe the various URL's for each table - or maybe use the Viewer URL's set up in the section editor? Something along the lines of this?

$searchTables['table1'] = array(
'viewerUrl' => 'detailPage1.php',
'titleField' => 'name',
'summaryField' => 'masthead',
'searchFields' => array('name','masthead','page_content','content'),
'detailPage' => 'permalink', //This is the permalink field
'indexPage' => 'indexPage1.php',
'checkfordetail' => 'content',

);
$searchTables['table2'] = array(
'viewerUrl' => 'detailPage2.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content','details'),
'detailPage' => 'detailPage2.php',
'indexPage' => 'indexPage2.php',
'checkfordetail' => 'details',

);

);
$searchTables['table3'] = array(
'viewerUrl' => 'detailPage3.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content','details'),
'detailPage' => 'detailPage3.php',
'indexPage' => 'indexPage3.php',
'checkfordetail' => 'details',

);

<?php if ($record['checkfordetail']): ?>
  <a href="<?php echo $record['detailPage'] ?>" style="color: #008000">DETAIL PAGE LINK IF THERE IS CONTENT IN THE "check for details"</a><br/><br/>
<?php else : ?>
  <a href="<?php echo $record['indexPage'] ?>" style="color: #008000">INDEX PAGE LINK IF 'check for details' IS EMPTY</a><br/><br/>
<?php endif ?>

Cheers,

Tim (toledoh.com.au)

By Damon - August 9, 2016

Hi Tim,

Give this a try. This code should do what you need. 

<?php if ($record['_summary']): ?>
     <a href="<?php echo $record['_link'] ?>" style="color: #008000"><?php echo $record['_link'] ?></a>

<?php else : //no summary content, then display alternate link based on table name ?>
   <?php if($record['tablename']     == "table1") : ?>
     <a href="indexPage1.php" style="color: #008000">Table1 Alternate Link</a>
   <?php elseif($record['tablename'] == "table2") : ?>
     <a href="indexPage2.php" style="color: #008000">Table2 Alternate Link</a>
   <?php elseif($record['tablename'] == "table3") : ?>
     <a href="indexPage3.php" style="color: #008000">Table3 Alternate Link</a>
   <?php endif; ?>

<?php endif ?>
<br /><br />

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/