0

I am creating an extension to save some data from orders through CT into a new db table.

My code is causing this error message:

Object of class CI_DB_mysql_result could not be converted to int

Here is my code:

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 if 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('exp_competition_purchase_upload_total');  

            // 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;

            }   

            $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);


        }
    }
}

I am fairly new to PHP, so I could be doing some stupidly wrong (more than likely).

Can anyone take a look and see if I am making any obvious errors here?

Thank you

2

This line here:

$upload_total = $this->EE->db->get('exp_competition_purchase_upload_total');

Is getting a result object, not the actual upload_total column. Change it to this to get the actual column value.

$upload_total = $this->EE->db->get('exp_competition_purchase_upload_total')->row('upload_total');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.