我試圖從一個表複製多個行到另一個,但它只保存我選擇的最後一個條目。當我打印所有顯示的數據時。我正在複製的表沒有設置auto_increment,這是我爲什麼猜測,所以現在我感到困惑。CakePHP沒有正確保存條目
foreach($this->request->data['Order']['archive_value'] as $orderid){
$data = $this->Order->query("select * from orders where orderid = '$orderid'");
$newdata = array(
'ArchivedOrder' => array(
'orderid' => $data[0]['orders']['orderid'],
'id' => $data[0]['orders']['id'],
'order_status' => $data[0]['orders']['order_status'],
'email' => $data[0]['orders']['email'],
'total' => $data[0]['orders']['total'],
'fullName' => $data[0]['orders']['fullName'],
'address' => $data[0]['orders']['address'],
'city' => $data[0]['orders']['city'],
'state' => $data[0]['orders']['state'],
'zip' => $data[0]['orders']['zip'],
'created' => $data[0]['orders']['created'],
'modified' => $data[0]['orders']['modified']
));
print_r($newdata); //this shows every entry that I look up, but it's not saving them properly
$this->loadModel('ArchivedOrder');
$this->ArchivedOrder->save($newdata);
///$this->Order->query("delete from orders where orderid = '$orderid'");
}
當我的phpMyAdmin轉儲表的結構這是顯示
CREATE TABLE `archived_orders` (
`orderid` int(10) default NULL,
`id` int(10) default NULL,
`order_status` varchar(20) default NULL,
`email` varchar(50) default NULL,
`total` varchar(50) default NULL,
`fullName` varchar(60) default NULL,
`address` varchar(50) default NULL,
`city` varchar(50) default NULL,
`state` varchar(50) default NULL,
`zip` varchar(15) default NULL,
`created` datetime default NULL,
`modified` datetime default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
沒有工作。我最終只是使用$ this-> ArchivedOrder-> query(「insert into ...」)來使它工作。 – user1443519
@ user1443519 - 不要使用「insert into ...」學會先使用Cake正確的方法。 – Dave