progress

When Mood Music
2013-04-12 01:05:00

update to previous report

More progress but blindingly slow. I am in deep loathing of PHP:

One of my functions gets a number of rows from a MySQL database. A number of rows can only be zero or a positive integer, depending on the SQL select instruction used. My select instruction narrows this range to 0 or 1, depending on whether a question has been answered correctly. And I’ve echoed both results to screen, many, many times – always 0 for an incorrect answer and 1 for a correct answer

So I should be able to do
if ($numrows = 1) {
$score++;  //update the student’s score

But that doesn’t work. This does:
if ($numrows > 0) {
$score++;  //update the student’s score

That cost me over 4 hours of hair-pulling.

Clumsy code
My code is pretty clumsy, I think. To mark a test of 20 questions:

  1. I set up two 1-D arrays, each of 20 elements. The first contains the student’s answers. The second contains text strings which are the same as the column headings in a MySQL table called wrongright.
  2. For each question, I compare the student’s answer (dragged back out of the first array) with the value dragged from a correct_answers table – this drag uses the contents of the second array. If the answer is correct (this is where the above moan happens),
    1. a variable for the student’s score for this test is incremented by 1
    2. ‘1’ is written to the the MySQL table, in the row for this test and the column for the question being processed.

    If the answer is incorrect, ‘0’ is written.

  3. When all the questions have been processed, the student’s final score is written to a students table, in the row for the current student and the column for this test.
  4. If the final score is greater than 19 (cos again normal integer arithmetic fails), the PHP code exits by sending an HTML page which congratulates the student. Otherwise the PHP code exits by sending an HTML page which tells the student he or she has failed the test.
  5. The ‘you have failed’ page contains many PHP nuggets.
    1. Most just include bits of HTML which are common to all pages – so if I decide to change one of these features, I only need to change one bit of code
    2. The first serious nugget calls the student’s screen name from session storage.
    3. The next calls a script to list the questions answered incorrectly. This code again has two arrays. The first is contains text strings which are the same as the column headings in wrongright. The second has text strings ‘question 01’, … ‘question 20’. For each question, if the relevant field in wrongright contains ‘0’, the relevant bit from the second array is called. So the student is told something like ‘You got the following questions wrong: question 01, question 07, question 20’.
    4. The next calls a script to retrieve this student’s score from the table of students. So the student is told ‘You scored $score out of 20.’
    5. The final one gives the student some feedback. It drags the score back from the table of students, then echoes an epithet back to the HTML page:
      • score < 20, epithet=” Not bad for a human. Miserable for a member of an intelligent species.”
      • score < 18, epithet= ” You must study harder.”
      • score < 15, epithet=” You must study much harder.”
      • score < 10, epithet=” petaQ! (Look it up.)”
      • score < 5), epithet=” You are a miserable excuse for a lobeless Ferengi.”

      This uses a chain of if statements because of my problems with PHP’s integer arithmetic. (It would be so much cleaner to use a switch statement.)

 

MoSCoW
Must

  • Find a way of sanitising input so that apostrophes don’t stuff up my code
  • Write appropriately sanitised answers. (The ‘correct’ answers are currently ‘A’, ‘B’, … , ‘T’)
  • Write history/culture lesson 1 and an unmarked history/culture assignment.

Should

  • language lesson 2
  • test 2
  • history/culture lesson 2 and its unmarked history/culture assignment.
  • A nice ‘you have finished – your final score for the whole scheme was …’ finishing page.

Could

  • language lessons 3-6
  • test 3-6
  • history/culture lesson 3-6 and their unmarked history/culture assignment.

Won’t

  • negative marking – deducting points from the student’s total score
  • if the adjusted total score falls below a certain percentage, send the student back to the beginning
  • a ‘thermometer’ in the right sidebar representing the student’s progress

 

Fun bits

  • the epithets
  • Microsoft = (translating the parts of the word, tunHom [tun = ‘soft’, -Hom = diminutive]).
  • ****ing evil computer = De’wI’ mIgh jay’
  • my code traps ‘out of cheese’ errors (should a certain PHP nugget fail to make contact with the database). All error traps enable users to email the webTribble

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.