Retrieve data from a field with multiple select

Retrieve data from a field with multiple select

GargiucnGargiucn Posts: 109Questions: 30Answers: 0

I'm trying to use multiple select dropdown to store multiple choices in a single field but I'm in trouble and I hope you can help me...

MySQL

TABLE `bandi`
  `ban_id` int(10),
  `ban_sogid` varchar(20)
  ...
  
Related TABLE `soggetti`
  `sog_id` tinyint(3)
  `sog_descr` varchar(30)

PHP

    Field::inst( 'bandi.ban_sogid' )
        ->options( Options::inst()
            ->table( 'soggetti' )
            ->value( 'sog_id' )
            ->label( 'sog_descr' ) 
            ->order( 'sog_descr ASC' )
        )
        ->validator( Validate::dbValues() )          

AJAX

Editor
    {
        label: "Soggetti:",
        name: "bandi.ban_sogid",
        type: "select",
        multiple: true,
        separator: ',',
    },   

Field bandi.ban_sogid after multiple selection: "1,2,3 "

In table view the name corresponding to the first value within the field bandi.ban_sogid appears correctly,
but I did not understand how and where to insert the code to visualize other values.

Thanks,
Giuseppe

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Hi Giuseppe,

    Can you show me your DataTable code that you are using to display the information? If you have 1,2,3 as the value, you will need to split that string on the comma and then look up the label for each one (assuming you don't also save the label in the same row in the db, which would be fairly pointless!).

    Allan

This discussion has been closed.