1

I managed to add a data from dropdown going to database. My problem is when I want to edit, I cant see the value from database that I add going to dropdown. I know that my problem lies in the edit_class_view.php file.

Here is my edit_class_view.php:

<div class="form-group"> <label class="control-label col-lg-2"> School Year-Semester:</label> <div class="col-lg-4"> <?php echo form_open('main/editClass'); $options = array( '' => 'Select School Year and Semester', 'SY 2016-2017 2nd Sem' => 'SY 2016-2017 2nd Sem', 'SY 2017 Summer' => 'SY 2017 Summer', 'SY 2017-2018 1st Sem' => 'SY 2017-2018 1st Sem', ); echo "<div class='drop_pos'>"; echo form_dropdown('sys', $options, 'class="btn dropdown-toggle"', 'required="required"', 'data-toggle="dropdown-menu"', '<?php echo $row->$School_Year_Semester;?>'); ?> <br> <div class="text-danger"><?php echo form_error('sys'); </div> </div> </div> </div> 
1
  • which version of Codeigniter? Commented Mar 1, 2017 at 10:02

1 Answer 1

1

Considering you are using Codeigniter 3. Please refer correct syntax of form_dropdown https://www.codeigniter.com/userguide3/helpers/form_helper.html

You need to do changes like. You have typo error in <?php echo $row->$School_Year_Semester;?>

$row->$School_Year_Semester it should be $row->School_Year_Semester

$selected = 'CSE'; // default value // check if row is set while editing; get its value if (isset($row->School_Year_Semester)) { $selected = $row->School_Year_Semester; } // Set all other attributes for dropdown $attribures = array("class" => "btn dropdown-toggle", "required" => "required" , "data-toggle" => "dropdown-menu"); echo form_dropdown('sys', $options, $selected, $attributes); 
Sign up to request clarification or add additional context in comments.

2 Comments

CSE is not included in my codes. It is only 'echo form_dropdown('sys', $options, 'class="btn dropdown-toggle"', 'required="required"', 'data-toggle="dropdown-menu"', '<?php echo $row->$School_Year_Semester;?>');'
Can you show what is print_r($row) also i have taken from your code only 'CSE' if its not there you can make other value as default selection

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.