php - my dropdown displays only one first alphabet of the data from the database

462

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" class="page_speed_788246959">
  <?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);
}   

}

?>

enter image description here

738

Answer

Solution:

Please use the folloing code:

get_Countries(){ $this->db->select('pkCountry,CountryName'); return $this->db->get('ISaathiDev.MCountry')->result_array(); }

People are also looking for solutions to the problem: post - PHP Dynamic signup page

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.