M5533 M5533 - 4 years ago 69
MySQL Question

Getting data in dropdown list from DB in Codeigniter

I have two tables in my database one is

and another one is
. So I have
in the
table. I want to get
in the requirements page dropdown list.

Here is my Controller code:

public function requirement() {

Model code:

function getusers() {
$query = $this->db->get();
echo $this->db->last_query();
return $query->result();

View code:

<div class="form-group">
<label>Select Vendor</label>
<select id="user_id" class="form-control" data-placeholder="user name" name="user_id" >
<option value="0"></option>

<?php foreach($user as $rows) { ?>
<option value="<?php echo $rows->user_id?>"><?php echo ucfirst($rows->first_name)?></option>
<?php } ?>

I got error in foreach loop

undefined variable data

please anyone help me..

Answer Source

simply use this function

    public function requirement() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download