Codeigniter – I’m having an issue with the dropdown it’s not populating the dropdown as expected, and I’m not sure what the exact problem is

When I tried to print the data, it is being printed correctly. However, I’m having trouble with the view file it’s not populating the dropdown as expected. If anyone knows what might be wrong, please let me know. I think it could be a silly mistake, but I’m not sure what it is. 😓

profile.php – view file

<body>
<!-- upload_form.php -->
<form method="post" action="<?php echo base_url('ImageUpload/add_image'); ?>" enctype="multipart/form-data" class="file-upload mb-5">
    <div class="container">
        <div class="row mb-5 gx-5">
            <!-- Contact detail -->
            <div class="col-xxl-8 mb-5 mb-xxl-0">
                <div class="bg-secondary-soft px-4 py-5 rounded">
                    <div class="row g-3">
                        <h4 class="mb-4 mt-0 fw-semibold">Contact detail</h4>
                        <!-- First Name -->
                        <div class="col-md-6">
                            <label class="form-label">First Name*</label>
                            <input type="text" class="form-control" placeholder="" name="first_name" aria-label="First name">
                        </div>
                        <!-- Last name -->
                        <div class="col-md-6">
                            <label class="form-label">Last Name*</label>
                            <input type="text" class="form-control" placeholder="" name="last_name" aria-label="Last name">
                        </div>
                        <!-- Phone number -->
                        <div class="col-md-6">
                            <label class="form-label">Phone number*</label>
                            <input type="text" class="form-control" placeholder="" name="phone_number" aria-label="Phone number">
                        </div>
                        <!-- Mobile number -->
                        <div class="col-md-6">
                            <label class="form-label">Mobile number*</label>
                            <input type="text" class="form-control" placeholder="" name="mobile_number" aria-label="Phone number">
                        </div>
                        <!-- Email -->
                        <div class="col-md-6">
                            <label for="inputEmail4" class="form-label">Email*</label>
                            <input type="email" class="form-control" id="inputEmail4" name="email_id">
                        </div>
                        <!-- Country -->
                        <div class="col-md-6">
                            <label class="form-label">Country*</label>
                            <select class="form-select" name="country">
                                <option value="">Select Country</option>
                            <?php if (!empty($countries)): ?>
                              <?php foreach ($countries as $country): ?>
                                <option value="<?php echo $country['country_id']; ?>">
                                  <?php echo $country['country_name']; ?>
                                </option>
                              <?php endforeach; ?>
                              <?php endif;?>
                            </select>
                        </div>
                        <!-- State -->
                        <div class="col-md-6">
                            <label class="form-label">State*</label>
                            <select class="form-select" name="state">
                                <option selected>Select State</option>
                                <option value="1">State 1</option>
                                <option value="2">State 2</option>
                                <!-- Add more options as needed -->
                            </select>
                        </div>
                        <!-- City -->
                        <div class="col-md-6">
                            <label class="form-label">City*</label>
                            <select class="form-select" name="city">
                                <option selected>Select City</option>
                                <option value="1">City 1</option>
                                <option value="2">City 2</option>
                                <!-- Add more options as needed -->
                            </select>
                        </div>
                    </div> <!-- Row END -->
                </div>
            </div>
            <!-- Upload profile -->
            <div class="col-xxl-4">
                <div class="bg-secondary-soft px-4 py-5 rounded">
                    <div class="row g-3">
                        <h4 class="mb-4 mt-0 fw-semibold">Upload your profile photo</h4>
                        <div class="text-center">
                            <!-- Image upload -->
                            <div class="square position-relative display-2 mb-3">
                                <!-- <i class="fas fa-fw fa-user position-absolute top-50 start-50 translate-middle text-secondary"></i> -->
                            </div>
                            <!-- Button -->
                            <input type="file" id="customFile" name="profile_image" hidden="">
                            <label class="btn btn-success-soft btn-block" for="customFile">Upload</label>
                            <button type="button" class="btn btn-danger-soft">Remove</button>
                            <!-- Content -->
                        </div>
                    </div>
                </div>
            </div>
        </div> <!-- Row END -->

        <!-- button -->
        <div class="gap-3 d-flex justify-content-center text-center">
            <button type="button" class="btn btn-danger">Delete profile</button>
            <button type="submit" class="btn btn-custom">Update profile</button>
        </div>
    </div> <!-- Container END -->
</form> <!-- Form END -->
</body>

Countries_data.php – Model

<?php
class Countries_data extends CI_Model {
  public function get_countries() {
   $sql = "SELECT country_id, country_name FROM tbl_countries";
   $query = $this->db->query($sql);

    return $query->result_array();
  }
}

?>

Countries.php – Controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Countries extends CI_Controller {
  public function __construct()
  {
      parent::__construct();
      $this->load->model('Countries_data');
  }

  public function index() {
      $data['countries'] = $this->Countries_data->get_countries();
      $this->load->view('profile', $data);
  }
}

?>

New contributor

Manish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật