Jump to content

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


Red2034
Go to solution Solved by objnoob,

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!

Link to comment
Share on other sites

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;?>
Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.