Welcome Guest, Not a member yet? Register   Sign In
Object of class stdClass could not be converted to int
#1

[eluser]The Revel[/eluser]
I am getting the following error:

Code:
A PHP Error was encountered
Severity: Notice
Message: Object of class stdClass could not be converted to int
Filename: controllers/auth.php
Line Number: 951
Here is my codeing:

Code:
//Update Balance
            
            $query = $this->db->select('balance')
                ->from('users')
                ->where('scancode', $scancode)
                ->get();
                if ($query->num_rows() > 0)
                {
                    $balance = $query->row();
                }
            
            
            //Add a single total transaction to the Transactions List    
            $full_tr = array('store_id' => $store_id,
                'scan_id' => $scancode,
                'amount' => $total,
                'date' => $date,
                'admin' => $this->input->post('admin'),
            );
            $this->db->insert('transactions', $full_tr);
            
             $new_balance = $balance + $total;
             $update_balance = array(
               'balance' => $new_balance
                );
             $this->db->where('scancode', $scancode);
             $this->db->update('users', $update_balance);

Line 951 pertains to:

Code:
$new_balance = $balance + $total;

The odd thing is, its doing all the calculations, its adding it to the database, but I get this notification error that it can't convert to an int. I tried:
Code:
$new_balance = (float) $balance + (float) $total;
as there are decimals in it, but that does nothing.

Basically what i am trying to do, is take 5 inputs, add them together and add that sum to the previous balance.
#2

[eluser]The Revel[/eluser]
Forgot the very first line of everything, how I get $total:
Code:
$total = (($this->input->post('qty1') * $this->input->post('pr1')) + ($this->input->post('qty2') * $this->input->post('pr2')) + ($this->input->post('qty3') * $this->input->post('pr3')) + ($this->input->post('qty4') * $this->input->post('pr4') + ($this->input->post('qty5') * $this->input->post('pr5')) + ($this->input->post('qty6') * $this->input->post('pr6')))) * -1 ;
#3

[eluser]CroNiX[/eluser]
All data coming from post is of type string, or boolean FALSE if it doesn't exist (do a var_dump()). You'd have to cast all of your $this->input->post() to float as well in your $total calculation if you want to do math on it.
#4

[eluser]Aken[/eluser]
In your query, you're setting $balance to your entire DB row (a stdClass object in this case). You want to do this:

Code:
$balance = $query->row()->balance;
#5

[eluser]The Revel[/eluser]
[quote author="Aken" date="1336606140"]In your query, you're setting $balance to your entire DB row (a stdClass object in this case). You want to do this:

Code:
$balance = $query->row()->balance;
[/quote]

This worked... I had forgot to post before everyone replied... I thought (at first) it was gonna give me just balance as I was selecting only balance... but this code made it work, thanks.




Theme © iAndrew 2016 - Forum software by © MyBB