Displaying multiple database result on Form/Select

Hello. I want to use a query result as the options of a select form. However, i am quite lost on how to achieve that purpose. Here's my current code :

$acc = new Select('account', AccountHistory::find(), array(
  'using'      => array('accID', 'accName-accNumber-bank'),
  'useEmpty'   => true,
  'emptyText'  => '...',
  'emptyValue' => '0'
));
$acc->setLabel('Select your account');
$this->add($acc);

And here's the AccountHistory model :

class AccountHistory extends Model{

    public $accID;
    public $userID;
    public $bank;
    public $accNumber;
    public $accName;

    public function initialize(){
        $this->skipAttributes(array('accID'));
    }
}

The desired select option is something like this : 'Steve-1234567890-Commonwealth Bank'.

Thanks in advance :D

Try in using key

array_column(AccountHistory::find()->toArray(), 'accName-accNumber-bank', 'accID')


2.7k

Try in using key

```php array_column(AccountHistory::find()->toArray(), 'accName-accNumber-bank', 'accID') ```

Sorry, i don't understand. Where should i put the using key ?

I was referring to the using key in the array, but is not correct. Try:

$acc = new Select('account', array_column(AccountHistory::find()->toArray(), 'accName-accNumber-bank', 'accID'), array(
  'useEmpty'   => true,
  'emptyText'  => '...',
  'emptyValue' => '0'
));


2.7k

I was referring to the using key in the array, but is not correct. Try:

```php $acc = new Select('account', array_column(AccountHistory::find()->toArray(), 'accName-accNumber-bank', 'accID'), array( 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '0' )); ```

No, it's not working. I think you have to use the using key in the array, because using my initial codes, there are spots that indicates something is fetch, just it is null. While going by your example, it doesn't show anything is fetched at all.

What Phalcn version are you using?



2.7k

What Phalcn version are you using?

2.0.0, the one on the homepage

I did not read the code for your model, the problem is that accName-accNumber-bank is not a property... if you want to display that properties in a string simply build the array first joining that propeties in a string



2.7k

I did not read the code for your model, the problem is that accName-accNumber-bank is not a property... if you want to display that properties in a string simply build the array first joining that propeties in a string

Sorry for the late reply.

Can you give an example how to do that ? I'm honestly kinda lost at the moment.