Skip to main content
Participant
April 30, 2012
Answered

How to display the total number of same text entries from a table (php)?

  • April 30, 2012
  • 4 replies
  • 995 views

Hello,

I have a database "choir" with the table "members" which has the following data structure:

NameVoice
Jennasoprano
Dannaalto
Roxyalto
Damientenor
Carmenalto
Daisysoprano

Diana

alto
Roberttenor
Johnbass

With Dreamweaver php, any help me on how can I display in a webpage the total number of "alto", in this case: 4.

Thanks,

Luci.

This topic has been closed for replies.
Correct answer sudarshan.t

SELECT voice, COUNT(*) as voice FROM choir GROUP BY voice ORDER BY voice DESC;

This will give you plain voiceid - count

SELECT voice, COUNT(*) as name FROM choir GROUP BY voice ORDER BY voice DESC;

This will give you name - voice - count

Trust it helps.

Cheers,

ST

4 replies

sudarshan.t
Inspiring
April 30, 2012

Create a new Recordset in Dreamweaver and run the following SQL:

SELECT voice, count(voice) AS voiceCount FROM choir GROUP BY voice
GreuceanuAuthor
Participant
April 30, 2012

Hi,

Thanks for your fast reply. I've used your proposal and it works fine.

However, I get only the value 4.

What I would like is:

alto 4

bass 1

soprano 2

tenor 2

Any help on how can I achieve this?

Thank you very much?

sudarshan.t
sudarshan.tCorrect answer
Inspiring
April 30, 2012

SELECT voice, COUNT(*) as voice FROM choir GROUP BY voice ORDER BY voice DESC;

This will give you plain voiceid - count

SELECT voice, COUNT(*) as name FROM choir GROUP BY voice ORDER BY voice DESC;

This will give you name - voice - count

Trust it helps.

Cheers,

ST