We help IT Professionals succeed at work.

PHP Poll with Question Branching

freezilla
freezilla asked
on
I need to develop a simple survey that will "grade" people based on their answers.  For instance if someone answers "Yes" (there will be all Y/N questions except the first question which will be Male/Female) they're given a "risk assessment".  No idea how to do that.

Anyone?
Comment
Watch Question

Why are you trying to build the survey script on you own. There are many available online for free... Google "PHP survey scripts"
Most Valuable Expert 2011
Top Expert 2016

Commented:
Google "Survey Monkey" for a good solution.  IIRC Constant Contact also has this ability.
Most Valuable Expert 2011
Top Expert 2016

Commented:
If you're just interested in learning the design pattern, you might find some of this article useful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_5256-Simple-Vote-Counting-in-PHP-and-MySQL.html
Commented:
Your risk assessment poll could follow this logic:

// get post vars
// assign values to all correct responses, like this, for instance
$correct_response = array(No, Yes, No, No, Yes, Yes);

// assign points for each response
$points = array(10, 20, 10, 20, 10, 10);

// loop through questions and determine if an answer was correct to add
for ($i = 0; $i <= 6; $i++)
{
  if ($_POST['response_$i'] == $correct_response[$i])
  {
    $total += $points[$i];
  }
}

echo 'total points '.$total;

// then you could do more, i.e. if points is greater than 40, make risk rating "A"
if ($total >= 40)
{
  $risk = 'A';
}

echo 'risk '.$risk;

Author

Commented:
Oh yeah.