Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter中将数据库内容从一个表复制到另一个表_Php_Mysql_Codeigniter - Fatal编程技术网

Php 在codeigniter中将数据库内容从一个表复制到另一个表

Php 在codeigniter中将数据库内容从一个表复制到另一个表,php,mysql,codeigniter,Php,Mysql,Codeigniter,我需要在单击存档按钮时将表内容从表:user\u openletter复制到表:country。如何编写一个查询,以便从、复制到、标题、openletter、openletter id从用户\u openletter复制到另一个表国家/地区。这是一个codeigniter应用程序 我的控制器代码是: public function store_user_data_archieve() { $match = $this->input->post('submit

我需要在单击存档按钮时将表内容从表:user\u openletter复制到表:country。如何编写一个查询,以便从、复制到、标题、openletter、openletter id从用户\u openletter复制到另一个表国家/地区。这是一个codeigniter应用程序

我的控制器代码是:

 public function store_user_data_archieve()       
 {
    $match = $this->input->post('submit');
    echo $match;
    if($match == "Archieve")
    {
        $data = array(
         'open_id' => $this->input->post('open_id'),
         'featured' => '1',
         'from' => $this->input->post('from'),
             'to' => $this->input->post('to'),
             'title' => $this->input->post('title'),

             'archieve' => '1',
             'latest' => '0',
             'sponsor' => 'images/sponsor.png'

           );
      $this->load->database();  
         //load the model  
         $this->load->model('select');  
         //load the method of model  
         $data['r']=$this->select->store_user_data_archieve($data);  
        echo "success";
        }
        else if(!$match == "new")
        {
            $data = array(
         'open_id' => $this->input->post('open_id'),
         'featured' => '1',
         'from' => $this->input->post('from'),
             'to' => $this->input->post('to'),
             'title' => $this->input->post('title'),
             'openletter' => $this->input->post('openletter'),
             'archieve' => '0',
             'latest' => '1',
             'sponsor' => 'images/sponsor.png'

           );
      $this->load->database();  
         //load the model  
         $this->load->model('select');  
         //load the method of model  
         $data['r']=$this->select->store_user_data_archieve($data);  
        echo "success";

        }
           else if(!$match == "Discard")
        {

        echo "failure";

        }

      }
我的查看代码是:

<?php  
         foreach ($r->result() as $row)  
         {  
        ?>

              <table border="1" cellpadding="4" cellspacing="0">
                <tr>
                    <td>from</td>
                    <td>to</td>
                    <td>title</td>
                    <td>openletter</td>
                    <td>Date & Time</td>
                    <td>open_id</td>
                </tr>

                    <tr>
                 <form action="/index.php/welcome/store_user_data_archieve" method="post">
                        <td><input type="text" name="from" value="<?php echo $row->from;?>" /></td>
                    <td><input type="text" name="to" value="<?php echo $row->to;?>" /></td>
                    <td><input type="text" name="title" value="<?php echo $row->title;?>" /></td>
                    <td><input type="text" name="openletter" value="<?php echo $row->openletter;?>" /></td>
                    <td><input type="text" name="datetime" value="<?php echo $row->datetime;?>" /></td>
                    <td><input type="text" name="open_id" value="<?php echo $row->open_id;?>" /></td>
                    <td><div><input type="submit" name="submit" value="Archieve" /></div></td>
                    <td><div><input type="submit" name="new" value="new" /></div></td>

                </form>
                </tr>
              </table>

         <?php } ?>

根据我们的讨论,您需要将从、到、标题、openletter、OpenU id从表用户\u openletter复制到国家/地区表


那么你有什么问题???我想我的型号代码有问题你想要什么???从哪个表复制到哪个表???复制字段-从,到,标题,openletter,open\u id从用户\u openletter复制到另一个表:Country是否检查我的答案?我收到此错误-此网页不可用错误内容\u解码\u失败
public function store_user_data_archieve($data)  
{  
 //data is retrieved from this query
$this->db->insert('country', $data);
$this->db->set('openletter');       
$this->db->select('openletter');
$this->db->where('open_id', $data[open_id]); 
$this->db->from('user_openletter');

// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
}  
$this->db->select('from,to,title,openletter,open_id');// select your filed
$q = $this->db->get('user_openletter')->result(); // get result from table
foreach ($q as $r) { // loop over results
        $this->db->insert('country', $r); // insert each row to country table
    }
$this->db->select('from, to, title,openletter, open_id');
$result_set = $this->db->get('user_openletter')->result();
if(count($result_set) > 0) {
   $this->db->insert_batch('country', $result_set);
}