我寫了一個功能,它的工作,除了一個部分:笨 - 無法查詢數據庫
//Find current upload total value
$this->EE->db->select('upload_total');
$upload_total = $this->EE->db->get_where('exp_competition_purchase_upload_total', array('member_id' => $member_id));
return $upload_total->result();
// If upload total is more than 0
if($upload_total > 0) {
$new_total = $upload_total + $my_data['upload_total'];
$my_data['upload_total'] = $new_total;
}
誰能告訴我,如果他們能看到的任何問題的代碼的這一特定部分?
這是完整的功能。它運行在一個擴展。該擴展正在工作,它似乎是上面的代碼,沒有。
我基本上只是試圖找到在數據庫中的值,然後如果該值是多個,將值添加到另一個。
function cartthrob_on_authorize()
{
foreach ($this->EE->cartthrob->cart->items() as $item) {
// Create array to store member id and purchased upload slots
$my_data = array(
'member_id' => $this->EE->session->userdata('member_id'),
'upload_total' => $item->item_options('fees'),
);
// Store member id in variable
$member_id = $my_data['member_id'];
// Query table to check if there is record with member id exists
$query = $this->EE->db->get_where('exp_competition_purchase_upload_total', array('member_id' => $member_id));
// If query returns more than 0 update record
if($query->num_rows() > 0) {
//Find current upload total value
$this->EE->db->select('upload_total');
$upload_total = $this->EE->db->get_where('exp_competition_purchase_upload_total', array('member_id' => $member_id));
// If upload total is more than 0
if($upload_total > 0) {
$new_total = $upload_total + $my_data['upload_total'];
$my_data['upload_total'] = $new_total;
}
return $upload_total->result();
$this->EE->db->where('member_id', $member_id);
$this->EE->db->update('exp_competition_purchase_upload_total', $my_data);
// If query returns 0 insert new record
} else {
$this->EE->db->insert('exp_competition_purchase_upload_total', $my_data);
}
}
}
是啊你不能運行代碼後,你已經返回...'返回$ upload_total->結果();'應該在你的條件語句 – mic
之後完成,當你調用'$ this-> EE-> db'時,你確定你有db的結果嗎? – rcpayan
micb:如果我在發生錯誤後添加它:CI_DB_mysql_result類的對象無法轉換爲int。 – ccdavies