# Writing a Questionnaire/Survey

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi,

Here's a worthy challenge for ya'll.  I'm trying to build a
questionnaire in php and need help understanding the logic behind the
process.  Here's an example that explains everything:

1) What quality is most important to you in a car?
a) Reliability
b) Affordability
c) Large size

2) How important is gas mileage?
a) Very important
b) Not at all important

If a user chooses 1a, 2b, the program writes "you will probably like a
Volvo SUV (reliable, gas-guzzling)".
If a user chooses 1b, 2a, the program writes "you will probably like a
Chevrolet Cavalier (cheap, efficient)".
If a user chooses 1c, 2b, the program writes "you will probably like a
GMC Yukon SUV (large, gas-guzzling)".
If a user chooses 1a, 2a, the program writes "you will probably like a
Honda Civic compact (reliable, efficient)".

... and so on ...

Basically, a user makes some radio-button choces, and the script
matches the choices to some database records filled with vehicle
information.  Because I want to have more than 2 questions, I can't
even begin imagining the difficulty of hard-coding all possible choices
- behold the power of a factorial :)

What would be the logic/algorithm for something like that?  What would
be the database structure?

## Re: Writing a Questionnaire/Survey

maxvalery@gmail.com wrote:

## Re: Writing a Questionnaire/Survey

omg, i wrote out this huge page of how i would implement your
questionaire..... but it somehow go lost because my 'Nickname'........
AHHHH!!!!!

## Re: Writing a Questionnaire/Survey

I feel so-o-o-o-o bad ... Thank you for trying!

## Re: Writing a Questionnaire/Survey

maxvalery@gmail.com wrote:

The logic is that of scoring and weighing.

First, you assign attribute scores to each vehicle (let's say, you have
three scores: reliability, fuel economy, and price, all on a scale from
1 to 10, with 1 being "extremely poor" and 10 being "excellent").  So
you have a table in a database with fields like this:

id (int)
make (varchar)
model (varchar)
year (int)
reliability (int)
economy (int)
price (int)

Then, you use user responses to elicit which score is most important to
a particular user (each question can add points to relative importance
of one or more scores).  How you weigh the results is entirely up to
you.  You can use raw points or simply give a weight of 3 to the most
important score, 2 to the next in order of importance, and 1 to the
least important.

Let's say you decided to store reliability, economy, and price weights
in three variables, \$w_reliability, \$w_economy, and \$w_price.  Now you
can form your query, execute it, and display results:

\$year = '2007';
\$query = <<<EOQ
SELECT make, model,
(\$w_reliability * reliability +
\$w_economy * economy +
\$w_price * price) AS composite_score
FROM vehicles
WHERE year = \$year
ORDER BY composite_score DESC
LIMIT 5
EOQ;
\$result = mysql_query(\$query);
echo "Your responses indicate that you might be interested in: \r\n";
while (\$record = mysql_fetch_array(\$result)) {
echo \$record['make'], ' ', \$record['model'], "\r\n";
}

Cheers,
NC

## Re: Writing a Questionnaire/Survey

Simply awesome.  Many thanks.

## Re: Writing a Questionnaire/Survey

I'm following you.

However, I don't understand how I would tie in the second question
about the importance of gas mileage.

Suppose I have the field 'mileage' in the database.  All vehicles are
scored on the 10-point scale depending on how gas-guzzling they are.
So a Cav is 7, Focus is 7, Civic is 8, Prius is 10, VW TDI is 10, Aveo
and Echo are 9, Ford F-150 is 2, Humscalade is 1, etc.

How would I tie that question in with the logic is the question asks
"important" or "not important"?  But even before that, what values do I
give to each radio button of each question?

Thanks again.

## Re: Writing a Questionnaire/Survey

If something is VERY IMPORTANT, give it a weight of, say, 10.
If something is IMPORTANT, give it a weight of, say 3.
If something is NOT IMPORTANT, give it a weight of about 0.
If something is UNDESIRABLE, give it a weight of, say, -3.
If something is VERY UNDESIRABLE, give it a weight of, say, -10.

The exact numbers are not critical and depend somewhat on how related
the characteristics are.  If you multiply all the weights on all
the questions by X (X a positive number), you really haven't changed
anything in the relative ranking.

If you're only going to give two levels of answer, e.g. price:
important or not important, low price should probably have some
positive weight even for those choosing "not important", since "not
important" is not equivalent to "don't care AT ALL" and there's no
other way to say "don't care AT ALL".

Sometimes people consider a feature normally thought of as desirable
as undesirable.  For example, HORSEPOWER is often thought of as
good, but if I'm buying a car for my teenage son, it's a NEGATIVE,
as I don't want him to even try hot-rodding with it.  Large size
might generally be considered a positive for a large family, but a
negative for a commuter who wants something easy to park in a small
space.  I don't know of anyone who thinks good gas mileage is a
negative for their own car except that good gas mileage might imply
non-sportiness.  I don't know of anyone who thinks higher price is
a good thing except that low price might imply unreliability.

Gordon L. Burditt

## Re: Writing a Questionnaire/Survey

TristaSD wrote:

It's entirely up to you.  You could say that "important" would add, say
7 points to the relative importance of fuel economy, while
"unimportant" would not change that weight.  Or, you could rewrite the
question to something like, "On a scale from 1 to 10 (1 being
absolutely unimportant and 10 being extremely important), how important
is fuel economy to you?" and put a <SELECT> menu next to it.

Cheers,
NC