Sql Table How To Multliply Array Of Numbers Fetched From Sql Table And Stored Into Array And Return
In a sql table how to multiply array of numbers fetched from sql table Table like given below Id country Person Money 1 UK john 2
Solution 1:
Assuming $myDatabase is a mySQLi connection.
This code is used to get money multiplied by a number.
$myNumber = 2;
$qry = "SELECT (Money * {$myNumber}) AS money
FROM Customers";
$result = $myDatabase->query($qry, MYSQLI_STORE_RESULT);
And this code is to store all money in array $arrayTotal.
while ($row = $result->fetch_object()) {
$arrayTotal[] = $row->money;
}
Hope this help.
Solution 2:
Why don't you try like this?
DECLARE @number int=2
SELECT Money * @number AS Money
FROM Customers;
And calculate sum form code. Otherwise try this
DECLARE @number int=2
SELECT SUM(Money * @number) AS total
FROM Customers;
Solution 3:
If you need to update the rows in the db instead of just getting the new value out, you can also do this in the database and it will be much faster than getting the data out and putting it back in.
UPDATE Customers SET Money = Money * 2
Post a Comment for "Sql Table How To Multliply Array Of Numbers Fetched From Sql Table And Stored Into Array And Return"