【问题标题】:How to show radio button from database using Codeigniter如何使用 Codeigniter 从数据库中显示单选按钮
【发布时间】:2014-12-15 01:07:55
【问题描述】:

我已阅读有关此的用户指南和教程,此时我还是代码点火器的新手,很难理解它, 如何签入单选按钮?

非常感谢

这是我的控制器

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');
	}
	
	}

还有这个观点

&lt;input type="text" name="jk" value="&lt;?php echo $detail-&gt;jk; ?&gt;"&gt;

【问题讨论】:

    标签: php codeigniter radio


    【解决方案1】:

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

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

    【讨论】:

    • 用这个父亲解决了 hoby== “拉里”)'); ?> />Lari hoby=="Berenang")'); ?> />Berenang
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多