Reputation: 413
i am trying to code in codeigniter using mysql database and using the html tags...now when i try to retrieve the data of the database to the dropdown it only displays the first alphabet.I am using the following code in VIEW
<select name="country" style="width: 200px;">
<?php
foreach($countries as $country)
{
echo '<option value="'.$country['PKCOUNTRY'].'">'.$country['COUNTRYNAME'].'</option>';
}
?>
</select>
MODEL
<?php
class Countries_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function get_countries() {
$query = $this->db->get('ISaathiDev.MCountry');
if ($query->num_rows >= 0)
{
foreach($query->result_array() as $row)
{
$data[$row['pkCountry']]=$row['CountryName'];
}
return $data;
}
}
} ?>
CONTROLLER
<?php
class countries extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Countries_model');
}
public function hey()
{
}
public function country()
{
//$this->load->view('u_view');
//log_message('debug', 'hey :Construct');
//$this->load->view('u_view');
$this->load->database();
$data['countries']=$this->Countries_model->get_countries();
$this->load->view('countries_view',$data);
}
}
?>
Upvotes: 0
Views: 302
Reputation: 4033
Please use the following php code:-
get_Countries(){
$this->db->select('pkCountry,CountryName');
return $this->db->get('ISaathiDev.MCountry')->result_array();
}
Upvotes: 0