Mysql
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Mysql

Cố gắng điền vào menu thả xuống trong codeigniter với dữ liệu mysql

Định dạng của bạn phải như thế này:

$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );

$shirts_on_sale = array('small', 'large');

echo form_dropdown('shirts', $options, 'large');

điều này sẽ tạo ra:

Đã chọn
<select name="shirts">
    <option value="small">Small Shirt</option>
    <option value="med">Medium Shirt</option>
    <option value="large" selected="selected">Large Shirt</option>
    <option value="xlarge">Extra Large Shirt</option>
</select>

THAM KHẢO TẠI ĐÂY

CẬP NHẬT

bạn cũng có thể thử điều này nếu bạn muốn

MÔ HÌNH

$this->db->select('airport_code, airport_name');
$this->db->order_by('airport_code', "asc");
$query = $this->db->get('airports');
if($query)
{
    $query = $query->result_array();
    return $query;
}

BỘ ĐIỀU KHIỂN

$query = $this->your_model->your_method();
if($query)
{
    $data['myDropdown'] = $query;
    $this->load->view('your_view', $data);
}

XEM - VẤN ĐỀ DROPDOWN CỦA BẠN

<select>
<?php 
    foreach($myDropdown as $dd)
        echo "<option value='". $dd['your_field'] ."'>". $dd['your_field'] ."</option>";
?>
</select>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Phím nước ngoài - Họ làm gì cho tôi?

  2. Làm cách nào để loại bỏ các ràng buộc khỏi bảng MySQL của tôi?

  3. Cách trừ ngày giờ hiện tại cho ngày giờ trong cơ sở dữ liệu - PHP

  4. Tìm kiếm bản ghi bằng dấu nháy đơn trong truy vấn giống như mysql

  5. Sử dụng biến phiên PHP trong tệp MySQL chạy bằng PHP?