【发布时间】:2014-06-28 06:27:34
【问题描述】:
如果我从一个表中删除一整行并将该行的两列值插入另一个表,我的模型函数结构应该是什么?我想使用活动记录。
function foo()
{
$this->db->truncate('to');
$query = $this->db->get('from')->result(); // get first table
foreach($query as $row) // loop over results
{
$this->db->insert('to', $row); // insert each row to another table
}
}
这是移动整行。我只想要两个特定的列。我该怎么办?
编辑 方法对吗?
public function refund()
{
$id = $this->uri->segment(4);
$data['accounts'] = $this->accounts_model->get_accounts_data_by_id($id);
foreach ($accounts as $row)
{
$data = array(
'barcode' => $row->barcode,
'refunded_amount' => $row->refunded_amount,
);
}
$this->db-insert('refund',$data);
}
【问题讨论】:
-
@AdrienXL 看看
-
看来我做错了。它不工作
标签: mysql codeigniter codeigniter-2