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

时间:2014-10-20 05:30:23

标签: php codeigniter radio

我已经阅读了有关此内容的用户指南和教程,此时我仍然是代码点火器中的新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');
	}
	
	}
&#13;
&#13;
&#13;

和这个观点

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

1 个答案:

答案 0 :(得分:0)

尝试此操作,在调用视图之前将其添加到控制器中

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

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