CodeIgniter Forums
How to retrieve employee id in a input box based on employee name drop down from database ?? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to retrieve employee id in a input box based on employee name drop down from database ?? (/showthread.php?tid=61007)

Pages: 1 2


How to retrieve employee id in a input box based on employee name drop down from database ?? - El Forum - 08-27-2014

[eluser]rainfall[/eluser]
Hmmm
j query is working Now after put the base_url in src.

But in input box its not showing the id ..

.its showing the name that i selected from the dropdown


How to retrieve employee id in a input box based on employee name drop down from database ?? - El Forum - 08-27-2014

[eluser]Flemming[/eluser]
Great! So now the input box is showing the correct name when you change the select?

Check this:

Code:
foreach($groups as $row)
            {
              echo '<option value="'.$row->employee_name.'">'.$row->employee_name.'</option>';
            }

You are using employee_name as the option value, so that is what will get inserted into the input box. You will need to change the option value to $row->employee_id (or whatever the ID field is called in the database)


How to retrieve employee id in a input box based on employee name drop down from database ?? - El Forum - 08-27-2014

[eluser]Flemming[/eluser]
The complete solution (and kind of like ivantcholakov suggested):

Model
Code:
$query = $this->db->query("SELECT emp_id,employee_name FROM tbl_sample ORDER BY employee_name");
return $query;

View
Code:
foreach($query->result() as $employee)
            {
              echo '<option value="'.$employee->emp_id.'">'.$employee->employee_name.'</option>';
            }



How to retrieve employee id in a input box based on employee name drop down from database ?? - El Forum - 08-27-2014

[eluser]rainfall[/eluser]
Wooowww .. its working now Smile

You guys are awesome

Thnx a lot