Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:09:15+00:00 2026-05-18T08:09:15+00:00

Im having a few problems with the form_dropdown function in CodeIgniter …. My application

  • 0

Im having a few problems with the form_dropdown function in CodeIgniter …. My application is in 2 parts, a user goes in, enters a form and submits it …. once its submitted a admin can go in and edit that persons form and then save it to database.

So, to display the dropdown in the initial form, im using the following ( all the options in the dropdown are coming from the database )

Model:

    function get_salaries_dropdown()
{
    $this->db->from($this->table_name);
    $this->db->order_by('id');
    $result = $this->db->get();
    $return = array();
    if($result->num_rows() > 0){
            $return[''] = 'please select';
        foreach($result->result_array() as $row){
            $return[$row['id']] = $row['salaryrange'];
        }
    }
    return $return;
}

Then in the Controller:

$data['salaries'] = $this->salary_expectation->get_salaries_dropdown();

Then finally the View:

<?php echo form_dropdown('salaries', $salaries, set_value('salaries', $salaries));  ?>

That bit works perfect in displaying the dropdown filled with values for the user to select.

So, when the user selects a value, then hits save, its saved to the database.

On the Edit page which the admin see’s, im using the same code to display the dropdown filled with options, but how do i get it to automatically choose the one thats been selected by the user in the initial stage?

Cheers,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:09:15+00:00Added an answer on May 18, 2026 at 8:09 am

    According to Codeigniter documentation

    The first parameter will contain the
    name of the field, the second
    parameter will contain an associative
    array of options, and the third
    parameter will contain the value you
    wish to be selected. You can also pass
    an array of multiple items through the
    third parameter, and CodeIgniter will
    create a multiple select for you.

    Your admin controller should have something like

    $data['selected'] = $this->salary_expectation->get_salary_selected();
    

    According to this, the admin view should be like this

    <?php echo form_dropdown('salaries', $salaries, $selected_value);  ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a few problems with an application that integrates sharepoint, SQL reporting services
I am having a few problems with Dojo Filtering Selects when using the Zend
Hi all having a few problems with my CSS I am trying to highlight
I'm having a form that takes a few seconds to finally display. This form
I'm having a windows form. In this form I've datagrid control which has few
Having a few problems with output buffering. Mainly, I'm trying to run output buffering
I'm having a few problems trying to position some div s in my website
I am having a few problems loading a table into the designer. I get
I am having a few problems with regex in C#. I require a string
hey stackoverflowers. im having a few problems with the code i have written to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.