I am creating a simple form with fields like First_name, Last_name, city etc.So for city field, I want to display dynamic data.Below is the code I am using it's in PHP CodeIgniter.
Controller Page:
public function city()
{
$this->load->model('dropdownM');
$getcity=$this->dropdownM->get_city();
$this->load->view('form1city',$getcity);
}
Model Page:
<?php
class DropdownM extends CI_Model
{
public function get_city()
{
$this->db->select('fname');
$this->db->from('city');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result();
}
}
}
View page:
<form action="<?php echo base_url(); ?>index.php/Rec/user" method="post">
<select class="form-control" id="city" name="city">
<option value="">Select </option>
<?php if(count($getcity)):?>
<?php foreach($getcity as $city):?>
<option value=<?php echo $city->c_id;?>><?php echo $village1->C_name;?></option>
<?php endforeach;?>
<?php else:?>
<?php endif;?>
</select>
<center>
<input type="submit" value="Submit" class="btn btn-bricky" id="subbtn"
name="submit1">
</center>
<form>
It's not displaying anything in the drop-down.I am not able to find out what the issue.