1. morgan_leecy
  2. Support
  3. Tuesday, September 12 2017, 11:11 AM
I am using a select box that is linked to a table in my component, and is mutli-select, value is the id (integrer) and label is the name of the item (string)

When I use JsnUser object to retrieve the field, it obviously returns the array of integrers. Is there a way to make JSN look up the labels or do I just have to write a model that uses the array of values in SQL i.e


$user=JsnHelper::getUser();

SELECT item_name
FROM table
WHERE id IN $user->my_list_of_items;

admin Accepted Answer
Admin
Hi,
sorry for late reply, unfortunately the only way is to get labels from DB; labels are stored in table "#__jsn_fields" column "params".

You can use this code to retrieve Label:


// PUT OPTIONS IN AN ARRAY
$db = JFactory::getDbo( ) ;
$query = $db->getQuery( true ) ;
$query->select('params')->from( '#__jsn_fields' )->where( 'alias = "employment"' ) ;
$db->setQuery( $query ) ;
$field_params = json_decode( $db->loadResult( ) ) ;
$field_options = explode( "\n",$field_params->select_options ) ;
$field_options_array = array () ;
foreach( $field_options as $opt ) {
$opt_tmp = explode( '|', $opt );
$field_options_array[ $opt_tmp[ 0 ] ] = $opt_tmp[ 1 ];
}

// SHOW LABEL
echo $field_options_array[ $user->employment ] ;

  1. more than a month ago
  2. Support
  3. # 1
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.