Jump to content

Copy one table row and add to another table...


Red2034

Recommended Posts

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!

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;?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.