could somebody help me, as I just very new in PHP
Description :-
What have I do :-
Thank in advance..
My Code :-
<?php
foreach($pdo->query("SELECT SUM(adult+child) FROM test WHERE testID = testID") as $totalpax) {
echo $totalpax['SUM(adult+cwhild)'];}
?>
SUM
is an aggregate function which totals all the rows for the given expression.
To get a value for each row separately simply add them:
SELECT adult+child as total FROM test
And then
echo $totalpax['total']
This is your query:
SELECT SUM(adult+child)
FROM test
WHERE testID = testID
Start with the WHERE
clause. It is comparing a problem to itself -- so this returns information from all rows where testID
is not NULL
.
What information does it return? That information is the SUM()
of two columns. This is an aggregation query that returns one row, which has one column which is the sum of adult + child
on basically all rows in the table.
Then, I try to make a calculation so that Totalpax filed get the amount from Adult + Child column.
As you have described the problem, you want an update
not a select
. That would be:
update test
set Totalpax = adult + child;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.