Welcome Guest, Not a member yet? Register   Sign In
matrix type of checkbox insert
#3

(This post was last modified: 07-05-2018, 08:36 AM by jreklund.)

You already got a thread regarding this. And you need to read up on SQL Injection, you are an easy target.
https://forum.codeigniter.com/thread-71053.html

But here it goes. As this is just one question and easier yo understand. :-)

https://www.codeigniter.com/user_guide/h...m_checkbox
PHP Code:
echo form_checkbox('matrix[]','1001010_5001',TRUE// TRUE = Checked
echo form_checkbox('matrix[]','1001010_5002',TRUE// TRUE = Checked
... 

PHP Code:
$matrix $this->input->post('matrix[]');
$insert = array();
foreach(
$matrix as m) {
 
   list($regno,$id) = explode('_',$m);
 
   $insert[] = array(
 
       'regno' => intval($regno);
 
       'id' => intval($id);
 
   );


Now $insert looks like this.

PHP Code:
array(
 
   array(
 
       'regno' => 1001010 
        
'id' => 5001
    
),
    array(
        'regno' => 1001010 
        
'id' => 5002
    
)
...
); 

Use insert_batch to insert it into the database.
https://www.codeigniter.com/user_guide/d...rting-data
PHP Code:
$this->db->insert_batch('stud'$insert);
// Produces: INSERT INTO stud (regno, id) VALUES ('1001010', '5001'),  ('1001010', '5002') 
Reply


Messages In This Thread
matrix type of checkbox insert - by kvanaraj - 07-05-2018, 04:48 AM
RE: matrix type of checkbox insert - by php_rocs - 07-05-2018, 08:25 AM
RE: matrix type of checkbox insert - by jreklund - 07-05-2018, 08:32 AM
RE: matrix type of checkbox insert - by kvanaraj - 07-05-2018, 10:20 PM
RE: matrix type of checkbox insert - by jreklund - 07-05-2018, 11:31 PM
RE: matrix type of checkbox insert - by kvanaraj - 07-05-2018, 11:46 PM
RE: matrix type of checkbox insert - by jreklund - 07-06-2018, 03:41 AM
RE: matrix type of checkbox insert - by kvanaraj - 07-06-2018, 05:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB