Red2034 Posted January 30, 2014 Share Posted January 30, 2014 So, I am displaying all the rows of data from one table and then I am trying to copy one table row (from 'class_master) into another table ('class') with the <a href btn code below... <?php $classesMaster = $this->db->get('class_master')->result_array(); foreach($classesMaster as $row):?> <tr> <td width="50" align="center"> <a href="#" class="btn btn-default btn-small"> <?php echo get_phrase('enroll'); $classes = $this->db->get('class')->result_array(); $data['deep_link'] = $classes->input->post('deep_link'); $data['title'] = $classes->input->post('title'); $data['class_id'] = $classes->input->post('class_id'); ?> </a> </td> </tr> <?php endforeach;?> I am able to add new data to any table with this function below so that is working fine, but not sure how to take data that already exists and move it to another table... function classes($param1 = '', $param2 = '') { if ($this->session->userdata('student_login') != 1) redirect(base_url(), 'refresh'); if ($param1 == 'create') { $data['title'] = $this->input->post('title'); $data['deep_link'] = $this->input->post('deep_link'); $data['teacher_id'] = $this->input->post('teacher_id'); $this->db->insert('class', $data); redirect(base_url() . 'index.php', 'refresh'); } any help would be great! Quote Link to comment Share on other sites More sharing options...
Red2034 Posted January 30, 2014 Author Share Posted January 30, 2014 let me simplify: I would like to copy certain data from one table to another and I have dumbed down my example to understand this a bit better: <?php $classes = $this->db->get('class')->result_array();?> <?php $classesMaster = $this->db->get('class_master')->result_array(); foreach($classesMaster as $row):?> <a href="index.php"><?php echo get_phrase('enroll'); $classesMaster['title'] = $classes->input->post['title'];?> </a> <?php endforeach;?> Quote Link to comment Share on other sites More sharing options...
Solution objnoob Posted January 30, 2014 Solution Share Posted January 30, 2014 Most RDBMS have syntax to accomplish this is one query! For example, in MySQL: INSERT INTO tblName1 (column1, column2) SELECT thisColumn1, thisColumn2 FROM tblName2; Visit http://dev.mysql.com/doc/refman/5.0/en/insert-select.html for more information on INSERT SELECT. In other RBDMS, such as SQLServer, this is known as a SELECT INTO. http://technet.microsoft.com/en-us/library/ms188029.aspx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.