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

  • Home
  • SEARCH
  • 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 6558703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:13:55+00:00 2026-05-25T13:13:55+00:00

I am trying to populate a dropdown list from database. In my view file

  • 0

I am trying to populate a dropdown list from database. In my view file I have the following code

$batch= $query ['batch']; // I pull this data from a separate model 
echo form_dropdown('shirts', $options, $batch);

Now the drop down list is populating data fine but the problem is I don’t get the value-“$batch” automatically selected when the page loads. Interestingly if I echo $batch, elsewhere in the page it shows the correct data, which means $batch is okay.

Here is my Controller

function update($id){
$this->load->model('mod_studentprofile');
             $data['query']= $this->mod_studentprofile->student_get($id);
             $data['options']= $this->mod_studentprofile->batchget();

             $data['tab'] = "Update Student Information";
                 $data['main_content']='update_studentprofile';
                 $this->load->view('includes/template',$data);
            }     

And here is my model

 function batchget() {

      $this->db->select('batchname');
       $records=$this->db->get('batch');

            $data=array();

                        foreach ($records->result() as $row)
                {
                    $data[$row->batchname] = $row->batchname;
                }

            return ($data);
        } 

Would you please kindly help me to solve this problem. I want to have the value- “$batch” automatically selected in the dropdown list when the page loads.

Thanks in Advance.

EDit… my Model for student_get($id)

  function student_get($id)
    {
        $query=$this->db->get_where('student',array('studentid'=>$id));
        return $query->row_array();
    }      

Thanks 🙂

  • 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-25T13:13:56+00:00Added an answer on May 25, 2026 at 1:13 pm

    I think that what’s probably happening is that the value in $batch may be matching what’s rendering in the dropdown but not the actual key in $options for that particular option which would be the value=”” portion of the html.

    for example…

    // this wouldn't select 'foo' as you may be thinking
    $options => array('0' => 'foo', '1' => 'bar');
    $batch = 'foo';
    echo form_dropdown('shirts', $options, $batch);
    
    // this would select foo
    $options => array('foo' => 'foo', 'bar' => 'bar');
    $batch = 'foo';
    echo form_dropdown('shirts', $options, $batch);
    

    Edit in response to OP’s comment:

    The batchget() method looks like it returns your $options array in the proper format and your student_get() method is returning a row_array. It appears that in the view you’re assigning the value of one of the keys returned by the student_get method to be the selected value stored in $batch which is then passed in as the third argument to form_dropdown().

    This all appears to be correct. As long as the value of $batch is indeed one of the array keys that is in $options then form_dropdown() will set one of the dropdown options as having been selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to populate a drop down list with data from an SQL database
I'm trying to populate a dropdown list in my web page from a mysql
I am trying to get the selected option from a dropdown and populate another
I'm trying to populate a List of beans from a form: public class Foo
I am trying to populate a dropdownlist with data pulled from a .resx file.
Background - I'm trying to populate a drop down list with state information from
I'm trying to populate a dropdown list control. 'Inputs' is the DB. Table is
I'm trying to populate a dropdown in my view. Any help is greatly appreciated.
I am trying to populate a second dropdown list based on the value of
I'm trying to populate a TDBGrid with the results of the following TQuery against

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.