Jump to content

Ferdinand

Members
  • Posts

    25
  • Joined

  • Last visited

Ferdinand's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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.
×
×
  • 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.