infrabyte Posted June 7, 2011 Share Posted June 7, 2011 Hi Guys, I have these two files one is a form with questions and the other is a results.php file. The form has 8 questions with 4 possible answers for each one namely a,b,c,d I have managed to get the results and display them but I want to say to the user that if mostly a's were selected then it must display what is given in my if..elseif...else loop for a and likewise for b,c or d here is my results file so far: <?php $title = "Quiz Results"; echo "<title>$title</title>"; // Below gets the answers from the page before // if (isset ($_POST['submit'])) { $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; $q4 = $_POST['q4']; $q5 = $_POST['q5']; $q6 = $_POST['q6']; $q7 = $_POST['q7']; $q8 = $_POST['q8']; } // Below checks to see if you forgot anything // if ($q1 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q2 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q3 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q4 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q5 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q6 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q7 == "") { die ("You forgot something, go back and check over your quiz."); } if ($q8 == "") { die ("You forgot something, go back and check over your quiz."); } // Below is where the answers are actually displayed // { echo<<<EOT <p>Results:<br> 1.) $q1<br> 2.) $q2<br> 3.) $q3<br> 4.) $q4<br> 5.) $q5<br> 6.) $q6<br> 7.) $q7<br> 8.) $q8</p> <p> EOT; } // This will give me a,b,c or d from each question $str1 = substr($q1, 0, 1); $str2 = substr($q2, 0, 1); $str3 = substr($q3, 0, 1); $str4 = substr($q4, 0, 1); $str5 = substr($q5, 0, 1); $str6 = substr($q6, 0, 1); $str7 = substr($q7, 0, 1); $str8 = substr($q8, 0, 1); // **************** Issue is from here on ******************************** $array = array($str1, $str2, $str3, $str4, $str5, $str6, $str7, $str8); $val = (array_count_values($array)); print_r ($val); // $val = min(array($str1, $str2, $str3, $str4, $str5, $str6, $str7, $str8)); // print_r ($val); if ($val=="a") echo "Mostly 'A's: IT. Looks like you're a bit of a tech-head. You should check out IT at Monash South Africa."; elseif ($val=="b") echo "Mostly 'B's: Business & Economics. Whoa, look out business world! You should check out Business & Economics at Monash South Africa."; elseif ($val=="c") echo "Mostly 'C's: Health Sciences. Open up and say, 'Aaaah.' You should check out Health Sciences at Monash South Africa."; elseif ($val=="d") echo "Mostly 'D's: Arts. Your engine runs on creative juice. You should check out the Arts at Monash South Africa."; else echo "You are a rare person with above normal interests, You should check out Monash South Africa."; ?> I have been trying various things but I think I am complicating the code to much or something....Please help me...much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/238633-php-quiz-with-no-database/ Share on other sites More sharing options...
requinix Posted June 7, 2011 Share Posted June 7, 2011 First step would be to (re)read the manual page for array_count_values(). Pay attention to the return value, and look to the example if you're still unsure how it works. Quote Link to comment https://forums.phpfreaks.com/topic/238633-php-quiz-with-no-database/#findComment-1226348 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.