1

I am attempting to create a dropdown filled with items from my database.

I have it populating but the values are ending up being the position in the array. i.e: 0, 1, 2, etc.

Here is my code for the form:

 echo form_open('main/generate_report'); $depts = array(); foreach ($my_depts->result() as $row) { $depts[] = $row->DEPT_NAME; } echo form_dropdown('dept_select', $depts); echo form_submit('report_submit', 'Generate Report'); 

it goes to this function when submitted:

echo '<h1><u>Report</u></h1>'; echo '<h2>'; echo $this->input->post('dept_select'); echo '</h2>'; 

for example when I select the first option named "test", it outputs 0 (its position in the array) rather than "test" like I want it to.

How do I adjust what the value is when populating the dropdown?

thank you in advance.

I am using Codeigniter 3.

0

1 Answer 1

1

Try below code. Use associative array for dropdown.

echo form_open('main/generate_report'); $depts = array(); foreach ($my_depts->result() as $row) { $depts[$row->DEPT_NAME] = $row->DEPT_NAME; } echo form_dropdown('dept_select', $depts); echo form_submit('report_submit', 'Generate Report'); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.