# Dropdown value for related database

**URL:** <https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737>\
**Category:** Need Help\
**Created:** [January 9, 2018, 9:34pm UTC](https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737 "2018-01-09T21:34:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mylos](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@mylos](https://discourse.cakephp.org/u/mylos)\
**Post date:** [January 9, 2018, 9:34pm UTC](https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737/1 "2018-01-09T21:34:09Z")

</div>

I baked an application based on these two tables

bookmarks

- id
- title
- person\_id

persons

- id
- name

when I now create a bookmark I have a dropdown to chose the person but instead of seeing the names I see the ids.  
How can I change it to see the names

View  
echo $this-\>Form-\>control(‘person\_id’, [‘options’ =\> $persons]);

Controller  
$persons = $this-\>Bookmarks-\>Persons-\>find(‘list’, [‘limit’ =\> 200]);

Thank you very much  
Mattia

---

<div class="post-metadata">

**Author:** ![deepvyas](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@deepvyas](https://discourse.cakephp.org/u/deepvyas)\
**Post date:** [January 10, 2018, 9:23am UTC](https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737/2 "2018-01-10T09:23:31Z")

</div>

In view file currently its $person=\> Id you have to pass $ person=\>Name

---

<div class="post-metadata">

**Author:** ![nuelibikunle](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/nuelibikunle/32/819_2.png) [@nuelibikunle](https://discourse.cakephp.org/u/nuelibikunle)\
**Post date:** [January 11, 2018, 9:26am UTC](https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737/3 "2018-01-11T09:26:32Z")

</div>

This is what you should do.

In your src/Model/Table/PersonsTable.php , in the initialize(), add the following if it is not there:

$this-\>setDisplayField(‘name’);  
$this-\>setPrimaryKey(‘id’);

// Prior to 3.4.0  
$this-\>displayField(‘name’);

So when you call

$persons = $this-\>Bookmarks-\>Persons-\>find(‘list’, [‘limit’ =\> 200]);  
$data = $persons-\>toArray();  
$data = [1 =\> ‘Person 1 Name’, 2 =\> ‘Person 2 Name’]  
You will have an array similar as below:

Details here - [https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#finding-key-value-pairs](https://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#finding-key-value-pairs)

---

<div class="post-metadata">

**Author:** ![mylos](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@mylos](https://discourse.cakephp.org/u/mylos)\
**Post date:** [January 11, 2018, 10:14pm UTC](https://discourse.cakephp.org/t/dropdown-value-for-related-database/3737/4 "2018-01-11T22:14:28Z")

</div>

Thanks, the change did exaclty what I was looking!
