sum of two column values in mysql using php
Posted: Mon Feb 13, 2017 1:47 pm
I am very thankful and grateful to this site and the moderators which have helped me alot i am still a beginner in php mysql
i will be very thankful if you could help in the following code
the error
Basically i want to add the values of two columns and print them
but the error i am facing is
Warning: Invalid argument supplied for foreach()
and neither its adding up
thanks alot in advance
i will be very thankful if you could help in the following code
the error
Code: Select all
<?php
$thehost = 'localhost';
$dbname = 'tutorial';
$username = 'root';
$userpass = '';
$dbh = new PDO ("mysql:host = $thehost ; dbname = $dbname", $username, $userpass)
or die ("Error");
foreach($dbh->query('SELECT SUM(option1+option2) FROM feedback') as $row)
{
echo "<tr>";
echo "<td>" . $row['SUM(option1+option2)'] . "</td>";
echo "</tr>";
}
?>
Basically i want to add the values of two columns and print them
but the error i am facing is
Warning: Invalid argument supplied for foreach()
and neither its adding up
thanks alot in advance