⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

copy button help please



DREON

DREON
  • profile picture
  • Member

Posted 16 February 2013 - 06:33 AM

I have a problem i want an action custom control called copy,

 

i mean i have 2 tables called sample1 and sample with column,, in my sample1 view i want to add a copy button the function is can send a copy of to my sample2 table.. please help..


victor

victor
  • profile picture
  • Member

Posted 16 February 2013 - 07:45 AM

   function test()
    {
	if ($this->uri->segment(3) == "copyrows")
	{
	    $row_id = $this->uri->segment(4);
	    $this->copyrows($row_id);
	    redirect('standby/test');
	}
	$crud = new grocery_CRUD();
	$crud->set_theme('datatables');
	$crud->set_table('standby');
	$crud->add_action('Send', '', 'standby/standby_v/copyrows', 'ui-icon-plus');
	$output = $crud->render();
	$this->load->view('standby/standby_v', $output);
	$this->load->view('layouts/footer');
    }

    function copyrows($id)
    {
         $data =  select from main table
         insert $data into second table
    }

DREON

DREON
  • profile picture
  • Member

Posted 20 February 2013 - 05:24 AM

sir what is the proper code i have my main table called faculty and seocd table is faculty_copy.

 

do i need to modify my model? thnx

 

$data = select from main table
insert $data
into second table


DREON

DREON
  • profile picture
  • Member

Posted 20 February 2013 - 05:29 AM

sir for more info: this my code on my

 

 public function faculty()
    
    {
    
        $crud = new grocery_CRUD();
 
        $crud->set_theme('datatables');
        $crud->set_table('faculty');
        $crud->set_subject('CMT');
        $crud->columns('id1','subject','days','schoolcollege_id','time_from','time_to','room');
        $crud->set_relation('id1','faculty_cmt','{faculty_lname},{faculty_fname}');    
        $crud->set_relation('schoolcollege_id','faculty_cmt','schoolcollege');    
    
        $crud->display_as('id1','Full Name');
        $crud->display_as('subject','Subject');
        $crud->display_as('days','Days');
        $crud->display_as('schoolcollege_id','School/College');
        $crud->display_as('time_from','From');
        $crud->display_as('time_to','To');
        $crud->display_as('room','Room');
        
        
        $output = $crud->render();
 
    
        $this->load->view('faculty_cmt.php',$output);    
        
    }

 

and i want to put a copy on my faculty_copy table


DREON

DREON
  • profile picture
  • Member

Posted 12 March 2013 - 02:50 AM

please help..


DREON

DREON
  • profile picture
  • Member

Posted 19 March 2013 - 12:55 PM

help please


davidoster

davidoster
  • profile picture
  • Member

Posted 19 March 2013 - 18:29 PM

The code was given here, /topic/1372-copy-button-help-please/#entry5793


DREON

DREON
  • profile picture
  • Member

Posted 19 March 2013 - 23:07 PM

i use this on my callback: buy then i click send button all record from my table1 will copy to my table2

 

my question is how can i copy and move Selected record to  my table2.

 

    $crud->add_action('Send', '', 'main/copyrows', 'ui-icon-plus');

 

 

function copyrows($primary_key)
    {   

    $query = $this->db->get('table1');
    foreach ($query->result() as $primary_key) {
          $this->db->insert('table2',$primary_key);
  }
    }


victor

victor
  • profile picture
  • Member

Posted 20 March 2013 - 09:29 AM

read how to get data from db . you don't understand how to do that.
http://ellislab.com/codeigniter/user-guide/database/index.html
and read how to insert data into a database

victor

victor
  • profile picture
  • Member

Posted 20 March 2013 - 09:35 AM

you should read how to get one row and about 'where' function.

DREON

DREON
  • profile picture
  • Member

Posted 20 March 2013 - 12:26 PM

i try to grocerycrud defult examples controler and i used this code to my copy add action

 

function copyrows($id) {
            $this->db->where('officeCode',$id);
            $rs = $this->db->get('offices')->result_array();
            
    
            $data['officeCode'] = $rs['officeCode'];
            $data['city'] = $rs['city'];
            $data['phone'] = $rs['phone'];
            $data['addressLine1'] = $rs['addressLine1'];
            $data['addressLine2'] = $rs['addressLine2'];
            $data['state'] = $rs['state'];
            $data['postalCode'] = $rs['postalCode'];
            $data['territory'] = $rs['territory'];

            
            $this->db->insert('offices1', $data);
        }

 

but i got this error:

 

Error Number: 1048

Column 'city' cannot be null

INSERT
INTO `offices1` (`officeCode`, `city`, `phone`, `addressLine1`,
`addressLine2`, `state`, `postalCode`, `territory`) VALUES (NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL)

Filename: C:\xampp\htdocs\CRUD\system\database\DB_driver.php

Line Number: 330


victor

victor
  • profile picture
  • Member

Posted 20 March 2013 - 13:04 PM

because you use result_array. You should use row_array to get one row. Read the user guards!

DREON

DREON
  • profile picture
  • Member

Posted 20 March 2013 - 23:18 PM

got it.. thnx


juanmoras

juanmoras
  • profile picture
  • Member

Posted 02 May 2013 - 10:59 AM

Thanks