counting diffrent values of a field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

counting diffrent values of a field

Post by pelegk2 »

can i in 1 select count all the values of a field that say equals 35
and how many are not?
thnaks in advance
peleg
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Try this

Post by Calimero »

FIRST you weren't clear is this MySQL table field or form processing textfield :lol:



Select count(column_name) from table_name where colum_name2='35' OR colum_name2<>'35';

OR you can use != instead of <>

Now you got the results, but decide on grouping to make them of any use for you

FOR EX.
//add this in the end of the MySQl statement
GROUP BY column_name2

Do report if this was usefull :D
Last edited by Calimero on Sun Jun 27, 2004 10:40 am, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

[mysql_man]count[/mysql_man]
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

but i want to count say :
all the cases that colum_name2=33
and all the cases that colum_name2=45
and know of each type how many i have
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try

Code: Select all

SELECT column_name, COUNT( column_name ) count FROM table_name GROUP BY column_name
seems to work for me..
Post Reply