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 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/

By Toledoh - August 9, 2016

Thanks Damon - that helped me a lot.

An important thing I figured out along the way is that you have to label additional queries as "field1", "field2" etc.

I was trying to figure out why this wouldn't work:

$searchTables['investments'] = array(
'viewerUrl' => 'detail-investments.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content','details'),
'field1' => 'permalink',
'check' => 'details',
);

and determined that just changing it to this solved my problems...

$searchTables['investments'] = array(
'viewerUrl' => 'detail-investments.php',
'titleField' => 'title',
'summaryField' => 'content',
'searchFields' => array('title','content','details'),
'field1' => 'permalink',
'field2' => 'details',
);

Cheers,

Tim (toledoh.com.au)