473,800 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting survey votes

Hi everyone,

Constructed a fairly big table with 20 rows, most of which are
TINYINTs based on user selection for a dropdown box. This is the form:

http://www.threechords.org/spb/survey/

Each field obviously corresponds to a row in the table, and the
majority are integers indicating the user's selection.

My issue is how to do meaningful stuff with the stored data. I believe
I need to use GROUP BY functionality but I'm not certain - how can I
calculate, say, the number of "1" ('Excellent') values for the field
"writing_qualit y"?

Matt

Jul 1 '07 #1
2 1755
>Constructed a fairly big table with 20 rows, most of which are
>TINYINTs based on user selection for a dropdown box. This is the form:

http://www.threechords.org/spb/survey/

Each field obviously corresponds to a row in the table, and the
majority are integers indicating the user's selection.
This doesn't really have that much to do with PHP; it's more related to
SQL and databases in general.
>My issue is how to do meaningful stuff with the stored data. I believe
I need to use GROUP BY functionality but I'm not certain - how can I
calculate, say, the number of "1" ('Excellent') values for the field
"writing_quali ty"?
select count(*) from survey where writing_quality =1;

If you want the whole distribution of votes:

select writing_quality , count(writing_q uality) from survey group by writing_quality ;

which will get you a list of writing_quality values and the number
of votes that gave that value, e.g.:

writing_quality count(writing_q uality)
1 32
2 86
3 74
4 50
5 22
7 1

(note: it seems nobody voted "6", so it is not listed).

If you want an overall average:

select avg(writing_qua lity) from survey;

which might give you 2.8 as an average.

You can also try things like:

select avg(writing_qua lity) from survey where sex = 'Male' and age >= 20 and age < 30;

which gives you a score from a specific segment of your users.

Jul 1 '07 #2
On Jul 1, 7:47 pm, gordonb.fs...@b urditt.org (Gordon Burditt) wrote:
Constructed a fairly big table with 20 rows, most of which are
TINYINTs based on user selection for a dropdown box. This is the form:
http://www.threechords.org/spb/survey/
Each field obviously corresponds to a row in the table, and the
majority are integers indicating the user's selection.

This doesn't really have that much to do with PHP; it's more related to
SQL and databases in general.
My issue is how to do meaningful stuff with the stored data. I believe
I need to use GROUP BY functionality but I'm not certain - how can I
calculate, say, the number of "1" ('Excellent') values for the field
"writing_qualit y"?

select count(*) from survey where writing_quality =1;

If you want the whole distribution of votes:

select writing_quality , count(writing_q uality) from survey group by writing_quality ;

which will get you a list of writing_quality values and the number
of votes that gave that value, e.g.:

writing_quality count(writing_q uality)
1 32
2 86
3 74
4 50
5 22
7 1

(note: it seems nobody voted "6", so it is not listed).

If you want an overall average:

select avg(writing_qua lity) from survey;

which might give you 2.8 as an average.

You can also try things like:

select avg(writing_qua lity) from survey where sex = 'Male' and age >= 20 and age < 30;

which gives you a score from a specific segment of your users.
Thank you very much, I've managed to construct a nice-looking page
(http://www.threechords.org/spb/survey/results.php) - apologies for my
poor group choice here.

Matt

Jul 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1663
by: sydemon | last post by:
Hello, I have the 3.2.2 version of the big nose bird survey script and have a problem with cookies. When i allow the survey users to view the results, the cookies work and prevent multiple votes. But when i send the users to a thank you page (via $JUMP_URL variable), the results are logged, but a cookie isn't dropped and the user can vote multiple times. Any suggestions, hints? http://bignosebird.com/carchive/survey.shtml
5
2200
by: spike29 | last post by:
Hello can any teach me how to make a survey like the one you see on ESPN. with color rows and and percentages on the side and the number of votes in XHTML :)
1
1445
nitindel
by: nitindel | last post by:
Hi All, Greetings...!!! I want to have a survey form in an asp Page..and when the user submits in any of the radio buttons..i want to show the results in percentage.. i have used the following code...but i want to make it more customized...please tell me some more links in related to this other than paid software.. <%
3
1515
by: nitric | last post by:
hey guys, i'm really stuck on this program. It's basically a survey and I have to ask people what drinks they like. 1-4, coffee tea oj and lemonade. i'm having trouble counting the TOTAL NUMBER OF PEOPLE and counting how many people pick coffee tea oj or lemonade. i have the 5th option set as a sentinel, where the program ends. i need help like i said counting the total number of people who participated(person who quits doesn't...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.