$order = new Application_Model_DbTable_Order();
$orderno = $order->select()
->from($order, 'orderno')
->where('memberid = ?', $userid)
->order('orderno DESC')
->limit(1, 0);
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'SELECT
ordertable
.orderno
FROMordertable
WHERE (memberid = '30') ORDER BYorderno
DESC LIMIT 1' for column 'orderno' at row 1SQLSTATE [HY000]:常規錯誤:不正確的1366整數值:
得到這個錯誤,我想知道如果有什麼錯我的代碼,因爲我已經到處找原因,但似乎並不找到任何幫助。
#SQL code for Ordertable#
`orderno` int(5) NOT NULL AUTO_INCREMENT,
`memberid` int(5) DEFAULT NULL,
PRIMARY KEY (`orderno`)
#SQL code for Item#
`itemid` int(5) NOT NULL AUTO_INCREMENT,
`image` varchar(100) NOT NULL,
`itemname` varchar(30) DEFAULT NULL,
`description` varchar(100) DEFAULT NULL,
`itemtype` varchar(20) DEFAULT NULL,
PRIMARY KEY (`itemid`)
#SQL code for Orderdetail#
`orderdetailno` int(5) NOT NULL AUTO_INCREMENT,
`orderno` int(5) NOT NULL,
`itemid` int(5) NOT NULL,
`unitcost` decimal(6,2) DEFAULT NULL,
PRIMARY KEY (`orderdetailno`),
KEY `orderno` (`orderno`),
KEY `itemid` (`itemid`)
這是我的sql代碼,如果它可以幫助我使用MySQL。
$request = new Zend_Session_Namespace('cart');
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$userid = $user->userid;
$order = new Application_Model_DbTable_Order();
$itemdb = new Application_Model_DbTable_Item();
$orderdetail = new Application_Model_DbTable_Orderdetail();
$data = array ('memberid' => $userid);
$order->insert($data);
$orderno = $order->select()
->from($order, 'orderno')
->where('memberid = ?', $userid)
->order('orderno DESC')
->limit(1, 0);
foreach ($request->array as $var)
{
$unitprice = $itemdb->select()
->from('$itemdb', 'unitcost')
->where('itemid = ?', $var);
$newArray = array('orderno' => $orderno,
'itemid' => $var,
'unitcost' => $unitprice,);
$orderdetail->insert($newArray);
}
任何指導將非常感激。
我的表:
你應該,如果你想在INSERT語句中使用它執行
$orderno
聲明和fetch()
結果只有2行,即orderno:1 memberid:30,orderno:2 memberid:30. – 2012-08-11 21:49:31你能發佈更多相關的代碼嗎?我認爲你正在執行錯誤的查詢。 – drew010 2012-08-11 22:30:00
已編輯我的代碼! – 2012-08-12 01:59:27