0

I have a sql table formatted like this:

YES NO
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.

4
  • 1
    Any error you are getting? or what result it's showing?. As per your code you $sql variable is only going to have the sum of "no" Commented May 19, 2017 at 4:51
  • what is the data type of the YES & NO column? It should be numeric data type and make sure the case type(upper/lower) in the query... Commented May 19, 2017 at 4:52
  • select sum(YES) as yes ,sum(NO) as no from votes Commented May 19, 2017 at 4:53
  • Where do you echo the results from the SQL query? Commented May 19, 2017 at 5:01

1 Answer 1

1

You should be able to sum both columns needed:

SELECT SUM(yes) AS yesSum, SUM(no) AS noSum FROM votes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.