8 posts by 2 authors in: Forums > CMS Builder
Last Post: January 29, 2015   (RSS)

Hi. I am using MultiSearch to search title and content, and would like to display a record's associated 'author' label (the person's name) in the search results. (I don't need to include the author field in the actual search.)

The following code results in error: "Undefined index: field1:label"

$searchTables['articles'] = array(
        'viewerUrl'       => '/articles/detail.php',
        'titleField'      => 'title',
        'summaryField'    => 'content',
        'field1'          => 'author',
        'searchFields'    =>  array('title','content'),
 ); 

<?php echo htmlencode($record['field1:label']) ?>
Results in error: "Undefined index: field1:label"

<?php echo htmlencode($record['field1']) ?>
Results in record value being displayed.

According to an older post, labels are not stored in the database. Is it possible to retrieve the label for display purposes only?

Thanks for any help!
~ Deborah

Hi Deborah - the :label field is only filled in when using getRecords. Are you using that function here?

--------------------

Claire Ryan
interactivetools.com

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

Claire, sorry to have not included that in my original post. I am using the following:

  // list of articles
  list($articlesRecords, $articlesMetaData) = getRecords(array(
    'tableName'   => 'articles',
    'orderBy'    => "date DESC",
    'useSeoUrls' => true,
  ));

~ Deborah
  

Okay, that's a little odd. Still though - you can get a list of the schema fields by using the following:

$fields = getSchemaFields($tablename);

From this, you can loop through the array until you get to the field you want, and then get the labels from that.

--------------------

Claire Ryan
interactivetools.com

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

Claire, I now understand why you said, "... that's a little odd." Your hint told me the code I had should work, so I did some testing and if the 'author' list values were to be managed from within the 'articles' table, the labels are displayed.

However, in my scenario, the 'authors' list choices are coming from an external table, as:

Section Editor: articles

Get options from database (advanced)
tablename: article_authors
option values: num
option labels: author_name_title

I would like to display the label for 'author_name_title' chosen in the 'articles' displayed on the search results page.

Considering these are possibly "related records", can what I want to accomplish still be done, or is the external table too far removed? (I hope I have the correct terminology. My apologies, if not.)

~ Deborah

Hi Deborah

No, this is fine, you can still do it. What you'll need to do is run a getRecords to get the author information, then sort the array by num so that it's easily accessible to the articles records.

This requires some knowledge of how arrays work, but it's nothing too difficult. Does that make sense?

--------------------

Claire Ryan
interactivetools.com

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

No bother, let me know if you're having problems with it.

Honestly - if you can wrap your head around array handling in PHP, you can do almost anything in your viewer files.

--------------------

Claire Ryan
interactivetools.com

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