ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.29k stars 1.35k forks source link

How to update a column by multiplying other 2 columns of each row? #962

Open CherukuriSiva opened 3 years ago

CherukuriSiva commented 3 years ago

I want to update one Cell in the row, by multiplying some other 2 cells like below.

UPDATE yourTable yt SET yt.Total = (yt.Pieces * yt.Price)

I tried below code:

   ` $last_id = $this->db->rawQuery('UPDATE bet_users_info bui SET bui.profit_amount = (bui.bet_amount * bui.cashout) where bui.betid = ?', 2);`

But I am receiving the error Undefined offset: 1 in \vendor\thingengineer\mysqli-database-class\MysqliDb.php on line 2056

I have no idea how to achieve this without Raw Query:


`        $update_profits_data = array(
            "profit_amount" => $bet_info_row["bet_amount"] * $bet_info_row["cashout"],
        );
        $this->db->where('betid', $bet_info_row["id"]);
        $last_id = $this->db->update('bet_users_info', $update_profits_data);
`

```Kindly let me know how to proceed further.