I have written a function, and it's working except one part:
//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;
}
Can anyone tell me if they can see any issue with this particular part of the code?
Here is the full function. It runs in an extension. The extension is working, it just appears to be the above code that isnt.
I am basically just trying to find the value in the db, then if the value is more than one, add the value to another.
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);
}
}
}