cocohead781 cocohead781 -4 years ago 104
MySQL Question

php add values and print

I have a sql table formatted like this:


1 0

0 1

1 0

and I'm trying to add up the yes and the no columns, then print the result. My current code looks like this:

$sql = "select sum(yes) from votes";
$sql = "select sum(no) from votes";

Any help?

EDITS: (responses to comments)

YES and NO are INT.

I get no error. It's just a blank screen.

I do not echo the results. The code above is the only code that has to do with this part.

Answer Source

You should be able to sum both columns needed:

SELECT SUM(yes) AS yesSum, SUM(no) AS noSum FROM votes
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download