Click here to Skip to main content
15,918,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
load saved value from Database into drop down in Edit form, I have tried in foreach and while loop both got error to load exact value in drop down

What I have tried:

$d['selecteddept'] = $this->db->query("SELECT e.id as eid,d.id as depid,d.name as depname from department d
  INNER JOIN employee_department ed on ed.department_id=d.id
  INNER JOIN employee e on e.id=ed.employee_id
  where ed.employee_id=". $e_id .";")->row_array();


<?php foreach ($selecteddept as $dpt) : ?>
                             <option selected="selected" value="<?= $dpt['id'] ?>"><?= $dpt['name']; ?></option>
                           <?php endforeach; ?>
Posted
Comments
Andre Oosthuizen 15-Feb-23 10:00am    
Need more information, what is the error, where does the error occur, is some data loading, is no data loading etc.
Member 11661832 15-Feb-23 12:15pm    
empty drop down value...no values are loaded in dropdown, I have already saved data in my database, I would like to edit data using edit details form, I want fetch the data from database into dropdown exactly which i have stored data earlier
Andre Oosthuizen 15-Feb-23 12:25pm    
Please update your comment to the question by clicking on the "Improve question" at the bottom of your question post.

Add your php code where you declared the $selecteddept and the code following that.
Add the error message and the line on which the error occured.
Richard Deeming 16-Feb-23 4:25am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900