/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] php/mysql get field totals

I am having a small issue trying to the of fields in a column that = 1

Here is what I have table with the name ‘table’ a column in that table called ‘active’ this column has two values 0 or 1

I would like to be able to get the total number of 1’s in that column

here is what I have at the moment and its not working correctly. Could someone help point out what I am doing wrong

[code=php]
// Test Active Start

$testTotactive = “SELECT count(*) as total_active
FROM table
WHERE active=0”;

// Test Active End

[/code]

Thank you

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@bluestartechDec 20.2008 — u need to define sRow as an array to accept data from mysql query
Copy linkTweet thisAlerts:
@mr_billauthorDec 20.2008 — I edited the post for the part I need help figuring out. The other part works if I could get it to retrieve the correct info from the database

[code=php]// Test Active Start

$testTotactive = "SELECT count(*) as total_active
FROM table
WHERE active = 1";


// Test Active End [/code]


having it like this I get the output of say 21 but what it counted was all the ones with a 0 not a 1 in that field so I dont know what to change to get the right output













****** got the results I wanted but dont understand why it works

using
[code=php]WHERE active = 1";[/code] i get all the ones with the number '0'

using
[code=php]WHERE active > 1";[/code] I get all the ones with the number '1'

Could someone explain to me first if this the proper way to do it and why it worked like this?
Copy linkTweet thisAlerts:
@OctoberWindDec 20.2008 — try using thi s
[code=php]
where active = '1'; // or active = '0';
[/code]


This will treat the value as a string, as opposed to an integer (or Boolean). 0 may be trying to find "null" values, and since everything is either a "0" or "1" there are no "null" values.
Copy linkTweet thisAlerts:
@mr_billauthorDec 21.2008 — Thank you for explaining that. Now it makes since.
×

Success!

Help @mr_bill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...