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

owfi6suc  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(106)

我已经阅读了用户指南和教程关于这一点,我仍然是新的bie在这个时候在代码点火器这么难理解它,我怎么能在单选按钮检查?
非常感谢
这是我的控制器

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; ?>">
zaq34kh6

zaq34kh61#

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

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

$data['jk']=form_radio($radio_data);

相关问题