Jump to content

Ferdinand

Members
  • Posts

    25
  • Joined

  • Last visited

Everything posted by Ferdinand

  1. I want to stick with arrays. I am assigned thje fisrt index of the array to zero to use it later as the correct answer among the other answers for computation purposes.
  2. Having these questions and answers hard coded. I want to be able to read them from a text file and load the arrays questions with questions from questions.txt while also read answers array from answers.txt. but at the same time maintain my data structures. How should I go abou this? <?php $questions = array('FTP','AJAX','RSS','XSS','PHP','W3C','XML','YUI','HTML','CGI','SSL','SQL','HTTP','CSS','SOAP','WAI','SSI','JSON','XSLT','WCAG'); $answers = array( // the correct answer for each question must be the first array item 0=>'item' array(0 =>'File Transfer Protocol','Force Through Privately','File Through Protocol','File Test Protocol'), array(0 => 'Asynchronous JavaScript and XML','All JavaScript and XML','Alternative Java and XML','Actual JavaScript and XML'), array(0 => 'Really Simple Syndication','Really Simple Scripting','Ready-Styled Scripting','Really Stupid Syndication'), array(0 => 'Cross-site Scripting','Cross-site Security','Cleverly Structured Scripting','eXtremely Safe and Secure'), array(0 => 'PHP: Hypertext Preprocessor','Post Hypertext Processor','Practical HTML Processing','Process HTML Prettily'), array(0 => 'World Wide Web Consortium','World Wide Web Committee','World Wide Web Creatives','Wakefield Willy Wavers Club'), array(0 => 'eXtensible Markup Language','eXtendable Markup Language','Crossover Markup Language','eXtreme Markup Language'), array(0 => 'Yahoo User Interface','Yahoo\'s Useful Idea','Yahoo Utility Interface','Yahoo User Interaction'), array(0 => 'Hypertext Markup Language','Human Markup Language','Helpful Markup Language','Hypertext Memory Language'), array(0 => 'Common Gateway Interface','Common or Garden Interaction','Computer\'s Graphical Intelligence','Common Graphical Interface'), array(0 => 'Secure Sockets Layer','Server Security Layer','Server Security Level','Secret Socket Layer'), array(0 => 'Structured Query Language','Stupid Query Language','Secure Query Language','Strict Query Language'), array(0 => 'Hypertext Transfer Protocol','Hypertext Traffic Protocol','HTML Traffic Transfer Protocol','HTML Through Traffic Protocol'), array(0 => 'Cascading Style Sheets','Custom Style Sheets','Clientside Style Sheets','Calculated Style Sheets'), array(0 => 'Simple Object Access Protocol','Structured Object Access Protocol','Simple, Objective And Private','Simply Obvious Access Principle'), array(0 => 'Web Accessibility Initiative','World Wide Accessibility Intiative','World Wide Accessibility Incorporation','Web Accessibility and Inclusion'), array(0 => 'Server-Side Include','Server-Side Intelligence','Scripted Server Include','Secure Server Include'), array(0 => 'JavaScript Object Notation','JQuery-Scripting Object Notation','Just Simple Object Notation','JavaScript Over the Net'), array(0 => 'eXtensible Stylesheet Language Transformation','eXpandable Stylesheet Language Transfer','eXtensible Stylesheet Language Transfer','eXtendable Stylesheet Language Transformation'), array(0 => 'Web Content Accessibility Guidelines','Wakefield Community Action Group','Web Criteria And Guidelines','World-wide Common Access Group') ); ?>
  3. I am talking about something like this http://quiz.elanman.com/
  4. Here is the text file file I am using: $string = 1) The most important feature of spiral model is: requirement analysis. Risk management. quality management. configuration management 2) The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3) One of the fault base testing techniques is: Unit testing. beta testing. Stress testing. mutation testing 4) A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing 5) RS is also known as specification of: White box testing. Stress testing. Integrated testing. Black box testing 6) Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7) FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9) Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability And the guidelines that I used to guide me in the text file. The questions will be finished with a colon(. The answers will be finished with a dot(.), all of them but the last one, as we will use the number of the question as separator. The questions or answers won't contain any numbers [0-9] or it will confuse the regex.
  5. 'm not well conversant with java or AJAX, but how can i read each line of a string display each line of question and answers at a time, after a user have answered the question id displays the next question upto the last one. Im using fget () in php to read line by line but dont know how to display one question and its respective answers at a time and be able to keep track of each submitted questions. Kindly assist with this I would highly appreciate. Here are the codes that I have: <?php $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); while (!feof ($openFile)) { $string = fgets($openFile). "<br />"; //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); // We prepare an array that will store the questions/answers $qas = array(); foreach($results[0] as $result) //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); //Looping through the array and outputting all the info into a form; $questionNr = 0; foreach($qas as $k=>$v) { echo "<input id='question{$questionNr}' style='width:40%' type='text' value='".$v['question']."' name='questions[]' >"; echo '<br /><br />'; //Puts the answers of each question unique and in the form of radios foreach($v['answers'] as $answer) { echo "<input type=\"radio\" name=\"selected_answers[$questionNr]\" value=\"$answer\" />"; echo "$answer"; echo '<br/><br />'; } $questionNr++; } } fclose ($openFile); ?> <input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers"> </form> </body> </html>
  6. A lot of coding there, Thanks it also gives me an insight of what to do in my processor.php Thanks for that. But actually its not what I want to accomplish. When I use the above codes that I had before, I display the questions as a block in the browser. But now using the function fget () and not fread () I want to loop my the questions one at a time and each can be submitted in each session as I progress through all of them up to the last one. Sounds a bit complicated by thats what actually I am trying to achieve. But I am really thankful and appreciate the efforts you are making jazzman1 to assist me crack this jazzman1.
  7. Thank you for the contribution jazzman1, What I am trying to do is to read the text file line by line. But I can only proceed to the next line only after I have answered a question of the first line, progressively upto the last one. Thank you.
  8. If I have the following text file. $string = '1) The most important feature of spiral model is: requirement analysis. Risk management. quality management. configuration management 2) The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3) One of the fault base testing techniques is: Unit testing. beta testing. Stress testing. mutation testing 4) A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing 5) RS is also known as specification of: White box testing. Stress testing. Integrated testing. Black box testing 6) Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7) FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9) Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability With the Regex below that I have, How do I loop through the regex to get my code display one question at a time. When I submit, I proceed to the next one. Thank you. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <style> style1 {font-family: "Baskerville Old Face"} .style2 { font-family: "Baskerville Old Face"; font-size: 12px; font-style: italic; } body { background-color: #99CC66; } #text_disabled{ border:0; font-size:10pt; color:black; } </style> <title>Question and Answer Read From Text File</title> </head> <body> <h3> Current Date and Time</h3> <p> <script language="javascript"> <!-- today = new Date(); document.write("The time now is: ", today.getHours(),":",today.getMinutes()); document.write("<BR>The date is: ", today.getDate(),"/",today.getMonth()+1,"/",today.getYear()); //--> </script> <form action="processor.php" method="POST"> <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br /> <?php $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); $string = fread($openFile, filesize("questionandanswers.txt")); //Loop through each line of every question //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); $qas = array(); // We prepare an array that will store the questions/answers foreach($results[0] as $result) { //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //removes unnecesary spaces in the questions $answers_array_trimmed = array_map('trim', $answers_array); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); } //Looping through the array and outputting all the info into a form; $questionNr = 0; foreach($qas as $k=>$v) { echo "<input id='question{$questionNr}' style='width:40%' type='text' value='".$v['question']."' name='questions[]' >"; echo '<br /><br />'; //Puts the answers of each question unique and in the form of radios foreach($v['answers'] as $answer) { echo "<input type=\"radio\" name=\"selected_answers[$questionNr]\" value=\"$answer\" />"; echo "$answer"; echo '<br/><br />'; } $questionNr++; } ?> <input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers"> </form> </body> </html>
  9. Thank you all for those who assisted me, I managed to figure it out. This is how i corrected it: In my form i changed the following line of code: echo "<input type=\"radio\" name=\"selected_answers[$questionNr]\" value=\"$answer\" />"; And POSTED it this way: $answers = $_POST['selected_answers']; It seemed the variable $questionNr with the curly braces were confusing me. Thanks again to you all.
  10. This is what is displayed when I print_r($_POST); Array ( [questions] => Array ( [0] => 1) The most important feature of spiral model is [1] => 2) The worst type of coupling is [2] => 3) One of the fault base testing techniques is [3] => 4) A fault simulation testing technique is [4] => 5) RS is also known as specification of [5] => 6) Which of these terms is a level name in the Capability Maturity Model? [6] => 7) FP-based estimation techniques require problem decomposition based on? [7] => What types of models are created during software requirements analysis? [8] => 9) Which of the following is not an attribute of software engineering ) [selected_answers] => Array ( [0] => " [1] => " [2] => " [3] => " [4] => " [5] => " [6] => " [7] => " [8] => " ) [submit] => Submit Answers ) And I am not sure where the variable is suppose to be declared, because in the other page is where it is declared.
  11. This is how I'm employing your method: //Posting of the chosen answers if(isset($_POST['submit'])) { echo '<b><u>THE ARE THE QUESTIONS IN THEIR ORDER</u></b><br />'; $question = $_POST['questions']; foreach($question as $quiz) { echo '<br />'; print_r($quiz); } $k='selected_answers'.$questionNr; $answers = $_POST[$k]; print_r($answers); But its still displaying the following error: ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined variable: questionNr in D:\wamp\www\frmfile\processor.php on line 33 And the following array: Array ( [0] => " [1] => " [2] => " [3] => " [4] => " [5] => " [6] => " [7] => " [8] => " )
  12. I have used it before and I get this error: SCREAM: Error suppression ignored for ( ! ) Notice: Undefined index: selected_answers$questionNr in D:\wamp\www\frmfile\processor.php on line 34
  13. Thank you for the insight Oaass, and where exactly I'm I suppose to apply the concept in my code? Thank you.
  14. How do I post the following through a form? $answers = $_POST['selected_answers$questionNr']; Every time I post the browser displays the following: see the following error Notice: Undefined index: selected_answers{$questionNr} This is the code I am using to $_POST the form output: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <style> style1 {font-family: "Baskerville Old Face"} .style2 { font-family: "Baskerville Old Face"; font-size: 12px; font-style: italic; } body { background-color: #99CC66; } #text_disabled{ border:0; font-size:10pt; color:black; } </style> <title>Question and Answer Read From Text File</title> </head> <body> <form action="processor.php" method="POST"> <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br /> <?php $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); $string = fread($openFile, filesize("questionandanswers.txt")); //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); $qas = array(); // We prepare an array that will store the questions/answers foreach($results[0] as $result) { //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //removes unnecesary spaces in the questions $answers_array_trimmed = array_map('trim', $answers_array); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); } //Looping through the array and outputting all the info into a form; echo "<script type=\"text/javascript\" src=\"js/form.js\"></script>"; $questionNr = 0; foreach($qas as $k=>$v) { echo "<input id='question{$questionNr}' style='width:40%' type='text' value='".$v['question']."' name='questions[]' >"; echo '<br /><br />'; //Puts the answers of each question unique and in the form of radios foreach($v['answers'] as $answer) { echo "<input type=\"radio\" name=\"selected_answers{$questionNr}[]\" value='\"' />"; echo "$answer"; echo '<br/><br />'; } $questionNr++; } ?> <input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers"> </form> </body> </html>
  15. Exactly, That's what I am trying to do. Thank you.
  16. I have managed to pass the form submission with the questions. What I'm trying to accomplish is to for each question, its subsequent answer chosen follows. This is what I have so far: These are the questions: 1) The most important feature of spiral model is2) The worst type of coupling is3) One of the fault base testing techniques is4) A fault simulation testing technique is5) RS is also known as specification of6) Which of these terms is a level name in the Capability Maturity Model?7) FP-based estimation techniques require problem decomposition based on? What types of models are created during software requirements analysis?9) Which of the following is not an attribute of software engineering These are the answers: THE ANSWERS YOU HAVE CHOSEN ARE: Data coupling Unit testing Mutation testing White box testing Ad hoc Information domain values Functional and behavioral Efficiency You Total Score is : 8 Now What I am trying to achieve is something like this: foreach ($question as quiz) { echo "echo $answers[]"; } Without interfearing with my codes. These are the codes that I have on the same so far: <html> <head> <title>Chosen Answers</title> <style > <!-- body { background-color: #00FFFF; } --> </style> </head> <body> <pre> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //Posting of the chosen answers if(isset($_POST['submit'])) { $question = $_POST['questions']; $answers = $_POST['selected_answers']; echo '<b><u>THE ANSWERS YOU HAVE CHOSEN ARE:</u></b><br /><br />'; $answers_trimmed = array_map('trim', $answers); } foreach($question as $quiz) { echo ($answers_trimmed); } //Opening of the answers file, reading and printing it $openFile = fopen("answers.txt", "r") or exit ("unable to open the answers file"); $fileContents = fread($openFile, filesize("answers.txt")); trim($fileContents); fclose($openFile); $delimiter = " "; $myArray = explode($delimiter, $fileContents); //Deletes unnecessary spaces in the read text files. $myArray_trimmed = array_map('trim', $myArray); //Computation of marks scored for the answered questions $score = 0; $no_questions = 9; for ($x = 0; $x < $no_questions; $x++) { if ($answers_trimmed [$x]== $myArray_trimmed[$x]) { echo "$answers_trimmed[$x]"; echo '<br />'; $score++; } } echo '<br />'; echo "<b>You Total Score is : <u>$score</u></b>"; ?> </pre> </body> </html>
  17. Thank you requinix I have sorted it out, but how do I separate the questions and answers such that for each questions the respective multiple answers are displayed together? Currently the output is as follows: 1) The most important feature of spiral model is 2) The worst type of coupling is 3) One of the fault base testing techniques is 4) A fault simulation testing technique is 5) RS is also known as specification of 6) Which of these terms is a level name in the Capability Maturity Model?7) FP-based estimation techniques require problem decomposition based on? What types of models are created during software requirements analysis?9) Which of the following is not an attribute of software engineering
  18. When is remove the disabled input and tries to print the $_POST questions this is the error i get: Notice: Undefined index: questions
  19. In the following code, When I try to pass questions together with the answers, only the answers are Posted as $_POST, How do $_POST the questions to from the form together with the answers? <html> <head> 03 <style> 04 #text_disabled{ 05 border:0; 06 font-size:10pt; 07 color:black; 08 } 09 </style> 10 <title>Question and Answer Read From Text File</title> 11 </head> 12 <body> 13 <form action="processor.php" method="POST" align="center"> 14 <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br /> 15 <?php 16 $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); 17 $string = fread($openFile, filesize("questionandanswers.txt")); 18 19 20 //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; 21 preg_match('/\d.*/', $string, $match); 22 23 //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; 24 preg_match_all('/\d\D*/', $match[0], $results); 25 26 $qas = array(); // We prepare an array that will store the questions/answers 27 foreach($results[0] as $result) 28 { 29 //Separating the question from the string with all the answers. 30 list($question, $all_answers) = explode(':', $result); 31 32 //Separating the different answers 33 34 $answers_array = explode('.', $all_answers); 35 36 //removes unnecesary spaces in the questions 37 38 $answers_array_trimmed = array_map('trim', $answers_array); 39 40 //Storing the question and the array with all the answers into the previously prepared array; 41 42 $qas[] = array('question' => $question, 'answers' => $answers_array); 43 } 44 45 //Looping through the array and outputting all the info into a form; 46 foreach($qas as $k=>$v) 47 { 48 echo "<input id='text_disabled' style='width:40%' type='text' value='".$v['question']."' name='questions[]' disabled>"; 49 echo "<select name='selected_answers[]'>"; 50 foreach($v['answers'] as $answer){ 51 echo "<option value='".$answer."'>".$answer."</option>"; 52 } 53 echo "</select>"; 54 echo "<br/><br/>"; 55 } 56 ?> 57 <input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers"> 58 </form> 59 </body> 60 </html> such that after $_POST I can do the following: if(isset($_POST['submit'])) {print_r($_POST['questions'])} and it prints the questions.
  20. I thinks it was some errors in the syntax. Thank you.
  21. Thanks to you all who have assisted me, Lemmin you gave me the idea and this is how I have implemented it $score = 0; $no_questions = 9; for ($x = 0; $x < $no_questions; $x++) { if ($answers_trimmed [$x]== $myArray_trimmed[$x]) { $score++; } } echo '<br />'; echo "<b><u>$score</u></b>";
  22. I have changed it as follows, but its still not computing the score, I don't know why < <html> <head> <title>Chosen Answers</title> </head> <body> <pre> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //Posting of the chosen answers $answers = $_POST['selected_answers']; echo '<b><u>THE ANSWERS YOU HAVE CHOSEN ARE:</u></b><br /><br />'; $answers_trimmed = array_map('trim', $answers); print_r($answers); //Opening of the answers file, reading and printing it $openFile = fopen("answers.txt", "r") or exit ("unable to open the answers file"); $fileContents = fread($openFile, filesize("answers.txt")); trim($fileContents); fclose($openFile); $delimiter = " "; $myArray = explode($delimiter, $fileContents); //Deletes unnecessary spaces in the read text files. $myArray_trimmed = array_map('trim', $myArray); print_r($myArray_trimmed); echo '*' . $answers[0] . '*' . $myArray_trimmed[0] . '*'; //Computation of marks scored for the answered questions $Total = 0; foreach ($answers as $i => $answer) { if ($answer == $myArray_trimmed[$i]) $Total++; } echo '<br /><br />'; echo "<b><u>$Total</u></b>"; ?> </pre> </body> </html> and the score is 0 >
  23. Hi I have these codes that try to compare content of array elements and add 1 for every similar comparison and zero for otherwise. But my codes seem not to be computing the final score, what could be the problem with my codes? Here are the codes: < <html> <head> <title>Chosen Answers</title> </head> <body> <pre> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //Posting of the chosen answers $answers = $_POST['selected_answers']; echo '<b><u>THE ANSWERS YOU HAVE CHOSEN ARE:</u></b><br /><br />'; print_r($answers); //Opening of the answers file, reading and printing it $openFile = fopen("answers.txt", "r") or exit ("unable to open the answers file"); $fileContents = fread($openFile, filesize("answers.txt")); trim($fileContents); fclose($openFile); $delimiter = " "; $myArray = explode($delimiter, $fileContents); $myArray_trimmed = array_map('trim', $myArray); print_r($myArray); echo '*' . $answers[0] . '*' . $myArray[0] . '*'; $score = $score1 = $score2 = $score3 = $score4 = $score5 = $score6 = $score7 = $score8 = 0; //Computation of marks scored for the answered questions if ($answers[0] == $myArray[0]) { $score = 1; } if ($answers[1] == $myArray[1]) { $score1 = 1; } if ($answers[2] == $myArray[2]) { $score2 = 1; } if ($answers[3] == $myArray[3]) { $score3 = 1; } if ($answers[4] == $myArray[4]) { $score4 = 1; } if ($answers[5] == $myArray[5]) { $score5 = 1; } if ($answers[6] == $myArray[6]) { $score6 = 1; } if ($answers[7] == $myArray[7]) { $score7 = 1; } if ($answers[8] == $myArray[8]) { $score8 = 1; } $Total = $score + $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8 ; echo '<br />'; echo "<b><u>$Total</u></b>"; ?> </pre> </body> </html> > What might be wrong with my codes? Thank you
  24. I have a text file that contains questions and answers: $string = '1) The most important feature of spiral model is: requirement analysis. Risk management. quality management. configuration management 2) The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3) One of the fault base testing techniques is: Unit testing. beta testing. Stress testing. mutation testing 4) A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing. 5) RS is also known as specification of: White box testing. Stress testing. Integrated testing. Black box testing 6) Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7) FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9) Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability' and the following code reads from the text file and puts in an html form format which can be posted: QUESTIONS AND ANSWERS QUIZ $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); $string = fread($openFile, filesize("questionandanswers.txt")); //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); $qas = array(); // We prepare an array that will store the questions/answers foreach($results[0] as $result) { //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); } //Looping through the array and outputting all the info into a form; foreach($qas as $k=>$v) { echo ""; echo "";foreach($v['answers'] as $answer){echo "".$answer."";}echo ""; echo " "; } ?> The problem is with the processor.php page which does not display the posted questions and answers and also does not compute the total score from the answers selected. these are the codes. [nobbc]
  25. I have a text file that contains questions and answers: $string = '1) The most important feature of spiral model is: requirement analysis. Risk management. quality management. configuration management 2) The worst type of coupling is: Data coupling. control coupling. stamp coupling. content coupling 3) One of the fault base testing techniques is: Unit testing. beta testing. Stress testing. mutation testing 4) A fault simulation testing technique is: Mutation testing. Stress testing. Black box testing. White box testing. 5) RS is also known as specification of: White box testing. Stress testing. Integrated testing. Black box testing 6) Which of these terms is a level name in the Capability Maturity Model?: Ad hoc. Repeatable. Reusable. Organized 7) FP-based estimation techniques require problem decomposition based on?: Information domain values. project schedule. software functions. process activities What types of models are created during software requirements analysis?: Functional and behavioral. Algorithmic and data structure. Architectural and structural. Usability and reliability 9) Which of the following is not an attribute of software engineering: Efficiency. Scalability. Dependability. Usability' and the following code reads from the text file and puts in an html form format which can be posted: <html> <head> <style> #text_disabled{ border:0; font-size:10pt; color:black; } </style> <title>Question and Answer Read From Text File</title> </head> <body> <form action="processor.php" method="POST" align="center"> <b><u> QUESTIONS AND ANSWERS QUIZ</u></b> <br /><br /> <?php $openFile = fopen("questionandanswers.txt", "r") or exit ("unable to open the text file"); $string = fread($openFile, filesize("questionandanswers.txt")); //Regex to get from the first number to the string's end, so we ignore the Number Question... bit; preg_match('/\d.*/', $string, $match); //We get all the strings starting with a number until it finds another number (which will be the beginning of another question; preg_match_all('/\d\D*/', $match[0], $results); $qas = array(); // We prepare an array that will store the questions/answers foreach($results[0] as $result) { //Separating the question from the string with all the answers. list($question, $all_answers) = explode(':', $result); //Separating the different answers $answers_array = explode('.', $all_answers); //Storing the question and the array with all the answers into the previously prepared array; $qas[] = array('question' => $question, 'answers' => $answers_array); } //Looping through the array and outputting all the info into a form; foreach($qas as $k=>$v) { echo "<input id='text_disabled' style='width:40%' type='text' value='".$v['question']."' name='questions[]' disabled>"; echo "<select name='selected_answers[]'>"; foreach($v['answers'] as $answer){ echo "<option value='".$answer."'>".$answer."</option>"; } echo "</select>"; echo "<br/><br/>"; } ?> <input name= "submit" type="submit" value="Submit Answers">&nbsp <input type="reset" value ="Clear Answers"> </form> </body> </html> The problem is with the processor.php page which does not display the posted questions and answers and also does not compute the total score from the answers selected. these are the codes. <pre> <?php $score = $score1 = $score2 = $score3 = $score4 = $score5 = $score6 = $score7 = $score8 = 0; if (isset($_POST['submit'])) { $answers = $_POST['selected_answers']; echo '<br />'; //First question if ($answers[0]=="risk management") { $score++; } elseif($answers[0]=="quality management") { $score--; } elseif($answers[0]=="configuration management") { $score --; } else { print_r($answers[0]); } echo '<br />'; //Second question if ($answers[1]=="Data coupling") { $score1 =1; } elseif($answers[1]=="Control coupling") { $score1 =0; } elseif($answers[1]=="Stamp coupling") { $score1 =0; } else { print_r($answers[1]); } echo '<br />'; //third question if ($answers[2]=="Unit testing") { $score2 =1; } elseif($answers[2]=="Beta testing") { $score2 =0; } elseif($answers[2]=="Stress testing") { $score2 =0; } else { print_r($answers[2]); } echo '<br />'; //fourth question if ($answers[3]=="Mutation testing") { $score3 =1; } elseif($answers[3]=="Stress testing") { $score3 =0; } elseif($answers[3]=="Black box testing") { $score3 =0; } else { print_r($answers[3]); } echo '<br />'; //fifth question if ($answers[4]=="white box testing") { $score4 =1; } elseif($answers[4]=="Stress testing") { $score4 =0; } elseif($answers[4]=="integrated testing") { $score4 =0; } else { print_r($answers[4]); } echo '<br />'; //sixth question if ($answers[5]=="Ad hoc") { $score5 =1; } elseif($answers[5]=="Repeatable") { $score5 =0; } elseif($answers[5]=="Reusable") { $score5 =0; } else { print_r($answers[5]); } echo '<br />'; //seventh question if ($answers[6]=="information domain values") { $score6 =1; } elseif($answers[6]=="project schedule") { $score6 =0; } elseif($answers[6]=="software function") { $score6 =0; } else { print_r($answers[6]); } echo '<br />'; //eigth question if ($answers[7]=="Functional and behavioral") { $score7 =1; } elseif($answers[7]=="Algorithmic and data structure") { $score7 =0; } elseif($answers[7]=="Architectural and structural") { $score7 =0; } else { print_r($answers[7]); } echo '<br />'; //nineth question if ($answers[8]=="Efficiency") { $score8 =1; } elseif($answers[8]=="Scalability") { $score8 =0; } elseif($answers[8]=="Dependability") { $score8 =0; } else { print_r($answers[8]); } } //code to generate the total score echo '<br />'; $Total = $score + $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8; echo '<br />'; echo '<b>Your Total score is: $Total </b>'; ?> </pre> What might be the problem. kindly assist me crack this out. Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.