如何使用Codeigniter显示数据库中的单选按钮


How to show radio button from database using Codeigniter

我已经阅读了关于这方面的用户指南和教程,我现在还是代码点火器的新手,所以很难理解它,我怎样才能按收音机登记?

非常感谢

这是我的控制器

public function updateProduct($id) 
	{
	 $data['product'] = $this->products_model->getProduct($id); 
     $this->load->view('update_product_view', $data);
	 }
	
	public function updateProductDb()
	{
	  $data=array(
					'nama'=>$this->input->post('nama'),
					'umur'=>$this->input->post('umur'),
					'hoby'=>$this->input->post('hoby'),
					'jk'=>$this->input->post('jk'),
					'alamat'=>$this->input->post('alamat'));
		 $condition['id'] = $this->input->post('id'); 
		$this->products_model->updateProduct($data, $condition);
		redirect('products'); 
		}

here is my model
<?php
//File products_model.php
	class Products_model extends CI_Model  {
		function __construct() { parent::__construct(); } function getAllProducts() {
		//select semua data yang ada pada table msProduct $this--->db->select("*");
		$this->db->from("anggota");
		return $this->db->get();
	}
	
	//iNI BERFUNGSI UNTUK GET DATA YANG DI PILIH BERDASARKAN ID ATAU USER YANG KLIK */
	function getProduct($id)
	{
		//select produk berdasarkan id yang dimiliki	
        $this->db->where('id', $id); //Akan melakukan select terhadap row yang memiliki productId sesuai dengan productId yang telah dipilih
        $this->db->select("*"); // SELECT ALL
        $this->db->from("anggota"); //TABEL
        
        return $this->db->get();
	}
	function addProduct($data)
	{
	//untuk insert ke database
	$this->db->insert('anggota',$data);
	}
	
	function updateProduct($data, $condition)
	{
		//update produk
        $this->db->where($condition); //Hanya akan melakukan update sesuai dengan condition yang sudah ditentukan
        $this->db->update('anggota', $data); //Melakukan update terhadap table msProduct sesuai dengan data yang telah diterima dari controller
	}
	function deleteProduct($id)
	{
		//delete produk berdasarkan id
        $this->db->where('id', $id);
        $this->db->delete('anggota');
	}
	
	}

和这个视图

<input type="text" name="jk" value="<?php echo $detail->jk; ?>">

试试这个,在调用视图之前将其添加到控制器中

    $radio_data = array(
    'name'        => 'jk',
    'id'          => 'jk',
    'value'       => $detail->jk,
    'checked'     => TRUE,
    'style'       => 'margin:10px',
    );
$data['jk']=form_radio($radio_data);