PHP word quiz using forms

  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

Hi,

I tried to script something in PHP,
without the tables and the other stuff this is it:

Code: [ Select ]
<?php
$Qword[0] = "sketch";
$Qword[1] = "regulations";
$Qword[2] = "excellent";
$Qword[3] = "staff";
$Qword[4] = "drawings";
$Qword[5] = "portfolio";

$i = 1;

$number = 0;
?>

<form name="list" action="list.php" method="post">

<?php
if($next){
switch($number){
case 0: echo $Qword[$number]; $number + $i; break;
case 1: echo $Qword[$number]; $number + $i; break;
case 2: echo $Qword[$number]; $number + $i; break;
case 3: echo $Qword[$number]; $number + $i; break;
case 4: echo $Qword[$number]; $number + $i; break;
case 5: echo $Qword[$number]; $number + $i; break;
}
}
?>


<input type="submit" name="next" value="Next" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >

</form>
  1. <?php
  2. $Qword[0] = "sketch";
  3. $Qword[1] = "regulations";
  4. $Qword[2] = "excellent";
  5. $Qword[3] = "staff";
  6. $Qword[4] = "drawings";
  7. $Qword[5] = "portfolio";
  8. $i = 1;
  9. $number = 0;
  10. ?>
  11. <form name="list" action="list.php" method="post">
  12. <?php
  13. if($next){
  14. switch($number){
  15. case 0: echo $Qword[$number]; $number + $i; break;
  16. case 1: echo $Qword[$number]; $number + $i; break;
  17. case 2: echo $Qword[$number]; $number + $i; break;
  18. case 3: echo $Qword[$number]; $number + $i; break;
  19. case 4: echo $Qword[$number]; $number + $i; break;
  20. case 5: echo $Qword[$number]; $number + $i; break;
  21. }
  22. }
  23. ?>
  24. <input type="submit" name="next" value="Next" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  25. </form>


What i meant it to do, is when you press the button "Next",
it shows a word. (whatever, really)
The first time display the word #1
Click on next again then display word #2 only

etc.etc.

It acts different,
purely this can be viewed [url=http://members.lycos.nl/dave90/list.php]here[/ur]

here it shows the first word over and over again,
or, it shows the first word only.

The difference is that #1 the script executes each time you press next, but by some mistake shows "script" (the first word) only, or, #2,
the script doesnt executes after the 1st(?) time.

I don't know what I'm doing wrong, id appreciate the help
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

You'll' need to save the value of the number that you're incrementing between executions of the script or it will just keep resetting every time you run the script. Also $number+$i isn't really doing anything because you're not saving the value. I think it would be simpler to just use one variable, increment it and pass it along in a hidden form field, so the new value will be available after the form is posted:
Code: [ Select ]
<?php
$Qword[0] = "sketch";
$Qword[1] = "regulations";
$Qword[2] = "excellent";
$Qword[3] = "staff";
$Qword[4] = "drawings";
$Qword[5] = "portfolio";

// set $number to zero if it isn't already set or is too high
if(!isset($number) || $number > 5)
{
    $number=0;
}
?>

<form name="list" action="list.php" method="post">

<?php
if($next){
switch($number){
case 0: echo $Qword[$number]; break;
case 1: echo $Qword[$number]; break;
case 2: echo $Qword[$number]; break;
case 3: echo $Qword[$number]; break;
case 4: echo $Qword[$number]; break;
case 5: echo $Qword[$number]; break;
}
// increment number by one (same as $number = $number + 1)
$number++;
}
?>

<input type="submit" name="next" value="Next" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
<input type="hidden" name="number" value="<? echo $number ?>">
</form>
  1. <?php
  2. $Qword[0] = "sketch";
  3. $Qword[1] = "regulations";
  4. $Qword[2] = "excellent";
  5. $Qword[3] = "staff";
  6. $Qword[4] = "drawings";
  7. $Qword[5] = "portfolio";
  8. // set $number to zero if it isn't already set or is too high
  9. if(!isset($number) || $number > 5)
  10. {
  11.     $number=0;
  12. }
  13. ?>
  14. <form name="list" action="list.php" method="post">
  15. <?php
  16. if($next){
  17. switch($number){
  18. case 0: echo $Qword[$number]; break;
  19. case 1: echo $Qword[$number]; break;
  20. case 2: echo $Qword[$number]; break;
  21. case 3: echo $Qword[$number]; break;
  22. case 4: echo $Qword[$number]; break;
  23. case 5: echo $Qword[$number]; break;
  24. }
  25. // increment number by one (same as $number = $number + 1)
  26. $number++;
  27. }
  28. ?>
  29. <input type="submit" name="next" value="Next" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  30. <input type="hidden" name="number" value="<? echo $number ?>">
  31. </form>
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

awesome, it works

thanks

however, i still would like too realise what i really did wrong.

alright, i get it now with setting $number.

however, was my way of doing $number + $1 really wrong, or is just $number++ easier?
And if doing it the way i wrote it doesnt really save it, why does it this way? ($number++)

Also, Im using Dreamweaver 4, not really for the buttons, but for the colors & lines.
But, whenever i write down something in PHP its all blue (the script part).
The comments too, are blue. Those should be grey. Im not sure if PHP code itself is divided in Dreamweaver.

Cause, I remember using some scripts (i pasted them into DW), and the comments were all in grey, and the code i believe had differences in colors too.
Does it need some indication of code?
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

You had $number + $i with $i holding the value of 1,
This is of course the same as $number + 1
That expression will generate a value of the current value of $number + 1, but you need to store the generated value back in $number like this:

$number = $number + $i;
or
$number = $number + 1;

You were just missing the $number = part (you don't need if for $number++; because it's basically a shorthand way of writing $number = $number + 1)

I'm not sure about your Dreamweaver question. I have DreamweaverMX and it does syntax highlighting on my code (although I don't really use it all that much). My version shows the comments in orange, php keywords in blue, and the opening and closing script delimiters in red. The indications of code should be the same as you used in that script - you shouldn't need to do anything special for dreamweaver that I'm aware of anyway.
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

weird, ill ask around

anyways, if you can miss a bit more of your spare time helping me out again, id appreciate it.

Ill explain some first, what this thing is meant to do is to display a word, you fill in the translation, click on "fill in", get the page showing if its wrong or good, and showing your answer and what the correct answer should be.

I inserted your code into that, but found out i had to make some changes.

code of showing the word follows:

Code: [ Select ]
<?php
$Qword[0] = "sketch";
$Qword[1] = "regulations";
$Qword[2] = "excellent";
$Qword[3] = "staff";
$Qword[4] = "drawings";
$Qword[5] = "portfolio";

$answer[0] = "schets";
$answer[1] = "regels";
$answer[2] = "geweldig";
$answer[3] = "medewerkers";
$answer[4] = "tekeningen";
$answer[5] = "verzamelmap";

// set $number to zero if it isn't already set or is too high
if(!isset($number) || $number > 5)
{
  $number=0;
}
?>

<form name="ordened" action="evaluation2.php" method="post">

<?php
if($next){
switch($number){
case 0: echo $Qword[$number]; break;
case 1: echo $Qword[$number]; break;
case 2: echo $Qword[$number]; break;
case 3: echo $Qword[$number]; break;
case 4: echo $Qword[$number]; break;
case 5: echo $Qword[$number]; break;
}
// increment number by one (same as $number = $number + 1)
$number++;
}
?>

<input type=hidden name=q value="<?php
if($next){
switch($number){
case 0: echo $Qword[$number]; break;
case 1: echo $Qword[$number]; break;
case 2: echo $Qword[$number]; break;
case 3: echo $Qword[$number]; break;
case 4: echo $Qword[$number]; break;
case 5: echo $Qword[$number]; break;

}
?>">

<input type=text name=fillin size="60">

<input type=hidden name=canswer value="<?php
if($next){
switch($number){
case 0: echo $answer[$number]; break;
case 1: echo $answer[$number]; break;
case 2: echo $answer[$number]; break;
case 3: echo $answer[$number]; break;
case 4: echo $answer[$number]; break;
case 5: echo $answer[$number]; break;
}
}
?>">

<input type="submit" name="invullen" value="Invullen" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">

</form>
  1. <?php
  2. $Qword[0] = "sketch";
  3. $Qword[1] = "regulations";
  4. $Qword[2] = "excellent";
  5. $Qword[3] = "staff";
  6. $Qword[4] = "drawings";
  7. $Qword[5] = "portfolio";
  8. $answer[0] = "schets";
  9. $answer[1] = "regels";
  10. $answer[2] = "geweldig";
  11. $answer[3] = "medewerkers";
  12. $answer[4] = "tekeningen";
  13. $answer[5] = "verzamelmap";
  14. // set $number to zero if it isn't already set or is too high
  15. if(!isset($number) || $number > 5)
  16. {
  17.   $number=0;
  18. }
  19. ?>
  20. <form name="ordened" action="evaluation2.php" method="post">
  21. <?php
  22. if($next){
  23. switch($number){
  24. case 0: echo $Qword[$number]; break;
  25. case 1: echo $Qword[$number]; break;
  26. case 2: echo $Qword[$number]; break;
  27. case 3: echo $Qword[$number]; break;
  28. case 4: echo $Qword[$number]; break;
  29. case 5: echo $Qword[$number]; break;
  30. }
  31. // increment number by one (same as $number = $number + 1)
  32. $number++;
  33. }
  34. ?>
  35. <input type=hidden name=q value="<?php
  36. if($next){
  37. switch($number){
  38. case 0: echo $Qword[$number]; break;
  39. case 1: echo $Qword[$number]; break;
  40. case 2: echo $Qword[$number]; break;
  41. case 3: echo $Qword[$number]; break;
  42. case 4: echo $Qword[$number]; break;
  43. case 5: echo $Qword[$number]; break;
  44. }
  45. ?>">
  46. <input type=text name=fillin size="60">
  47. <input type=hidden name=canswer value="<?php
  48. if($next){
  49. switch($number){
  50. case 0: echo $answer[$number]; break;
  51. case 1: echo $answer[$number]; break;
  52. case 2: echo $answer[$number]; break;
  53. case 3: echo $answer[$number]; break;
  54. case 4: echo $answer[$number]; break;
  55. case 5: echo $answer[$number]; break;
  56. }
  57. }
  58. ?>">
  59. <input type="submit" name="invullen" value="Invullen" size=10 >
  60. <input type="hidden" name="number" value="<? echo $number ?>">
  61. </form>


Code of evaluation:

Code: [ Select ]
<?php
if($fillin != $canswer){
//answer is incorrect
echo "Fout!<br>Klik op Volgende om verder te gaan";
} else {
//answer is correct
echo "Goed!<br>Klik op Volgende om verder te gaan";
}
?>

<form name="Volgende" action="ordened.php" method="post">
<input type="submit" name="next" value="Volgende" size=10 >
</form>

<?php echo $fillin ?> //shows what you filled in

<?php echo $canswer ?> //shows correct answer
  1. <?php
  2. if($fillin != $canswer){
  3. //answer is incorrect
  4. echo "Fout!<br>Klik op Volgende om verder te gaan";
  5. } else {
  6. //answer is correct
  7. echo "Goed!<br>Klik op Volgende om verder te gaan";
  8. }
  9. ?>
  10. <form name="Volgende" action="ordened.php" method="post">
  11. <input type="submit" name="next" value="Volgende" size=10 >
  12. </form>
  13. <?php echo $fillin ?> //shows what you filled in
  14. <?php echo $canswer ?> //shows correct answer


I know, its easier to display the word in a text field immediately, so I dont need to create a whole new hidden field, but it looks better, and its the way i prefer to do it.

For the hidden field holding the value of the word (finding it the way by calculating it just like the code that displays is) and the answer (calculated same way too) i removed the part of increasing $number, cause that would mean each field would hold a different value, right? (different word thus)

Document that displays the word
Document that evaluates the form, and after showing results directs you back to the word displayer
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Ok, I think I understand. You will need to remove the if($next) clauses or else the first time the person views the page $next won't have any value (unless the form is submitting to itself that won't work at all). You will also need to move the $number++; to the very end of the script, so that it is incremented only after everything else is done.

Also if the second file is going to return the user back to try another word then it will have to store the value of $number in a hidden field also. That way the number value will be bounced back and forth between the two pages, and be incremented only after the important script in the first page has run.

Code: [ Select ]
<?php
$Qword[0] = "sketch";
$Qword[1] = "regulations";
$Qword[2] = "excellent";
$Qword[3] = "staff";
$Qword[4] = "drawings";
$Qword[5] = "portfolio";

$answer[0] = "schets";
$answer[1] = "regels";
$answer[2] = "geweldig";
$answer[3] = "medewerkers";
$answer[4] = "tekeningen";
$answer[5] = "verzamelmap";

// set $number to zero if it isn't already set or is too high
if(!isset($number) || $number > 5)
{
  $number=0;
}
?>

<form name="ordened" action="evaluation2.php" method="post">

<?php echo $Qword[$number] ?>

<input type=text name=fillin size="60">

<input type=hidden name=q value="<?php echo $Qword[$number] ?>">

<input type=hidden name=canswer value="<?php echo $answer[$number]; $number++;?>">

<input type="submit" name="invullen" value="Invullen" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">
</form> 
  1. <?php
  2. $Qword[0] = "sketch";
  3. $Qword[1] = "regulations";
  4. $Qword[2] = "excellent";
  5. $Qword[3] = "staff";
  6. $Qword[4] = "drawings";
  7. $Qword[5] = "portfolio";
  8. $answer[0] = "schets";
  9. $answer[1] = "regels";
  10. $answer[2] = "geweldig";
  11. $answer[3] = "medewerkers";
  12. $answer[4] = "tekeningen";
  13. $answer[5] = "verzamelmap";
  14. // set $number to zero if it isn't already set or is too high
  15. if(!isset($number) || $number > 5)
  16. {
  17.   $number=0;
  18. }
  19. ?>
  20. <form name="ordened" action="evaluation2.php" method="post">
  21. <?php echo $Qword[$number] ?>
  22. <input type=text name=fillin size="60">
  23. <input type=hidden name=q value="<?php echo $Qword[$number] ?>">
  24. <input type=hidden name=canswer value="<?php echo $answer[$number]; $number++;?>">
  25. <input type="submit" name="invullen" value="Invullen" size=10 >
  26. <input type="hidden" name="number" value="<? echo $number ?>">
  27. </form> 


Code: [ Select ]
<?php
if($fillin != $canswer){
//answer is incorrect
echo "Fout!<br>Klik op Volgende om verder te gaan";
} else {
//answer is correct
echo "Goed!<br>Klik op Volgende om verder te gaan";
}
?>

<form name="Volgende" action="ordened.php" method="post">
<input type="submit" name="next" value="Volgende" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">
</form>

<?php echo $fillin ?> //shows what you filled in

<?php echo $canswer ?> //shows correct answer
  1. <?php
  2. if($fillin != $canswer){
  3. //answer is incorrect
  4. echo "Fout!<br>Klik op Volgende om verder te gaan";
  5. } else {
  6. //answer is correct
  7. echo "Goed!<br>Klik op Volgende om verder te gaan";
  8. }
  9. ?>
  10. <form name="Volgende" action="ordened.php" method="post">
  11. <input type="submit" name="next" value="Volgende" size=10 >
  12. <input type="hidden" name="number" value="<? echo $number ?>">
  13. </form>
  14. <?php echo $fillin ?> //shows what you filled in
  15. <?php echo $canswer ?> //shows correct answer


I think that's it anyway.
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

Youre most thankful once again :wink:

but heres another thing, and i apologise for keeping bothering you;

It would be quite efficient if the user would not need its mouse.
This would mean that the text field should be automatically selected, and so should be the "fill in" button, and on the evaluation page the "next" button.

I think ive seen it that a field is already selected, i tried some theories myself but none worked.

Also, on the buttons, it might not be needed for them to be selected, but, im not sure if its possible, they could hold a hotkey. (enter / return is sort of a hotkey when the button is selected)

Anything?
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

You can set the focus on a text field or button using javascript. For the first file where you want to set the focus on the text field you could add the following scriipt after the text field is created:

Code: [ Select ]
<input type="submit" name="invullen" value="Invullen" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">

</form>

<script type="text/javascript">
<!--
document.ordened.fillin.focus();
-->
</script>
  1. <input type="submit" name="invullen" value="Invullen" size=10 >
  2. <input type="hidden" name="number" value="<? echo $number ?>">
  3. </form>
  4. <script type="text/javascript">
  5. <!--
  6. document.ordened.fillin.focus();
  7. -->
  8. </script>


and for the second file you could add the following script:

Code: [ Select ]
<form name="Volgende" action="ordened.php" method="post">
<input type="submit" name="next" value="Volgende" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">
</form>

<script type="text/javascript">
<!--
document.Volgende.next.focus();
-->
</script>
  1. <form name="Volgende" action="ordened.php" method="post">
  2. <input type="submit" name="next" value="Volgende" size=10 >
  3. <input type="hidden" name="number" value="<? echo $number ?>">
  4. </form>
  5. <script type="text/javascript">
  6. <!--
  7. document.Volgende.next.focus();
  8. -->
  9. </script>


There is actually more than one method of doing this with javascript, but with the code examples you've shown me this method is the most straightforward. The only real requirement to doing it this way is that the javascript must be outside the php code and be after the form elements that are being referred to have been created (you can't set the focus on something that doesn't exist yet). This should allow your users to go back and forth without needing to use the mouse. Pressing the enter key will be the same as clicking the button on the second form and the cursor will automatically appear inside the text field on the first form .
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

You're the man.
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

I hate keeping you busy on this one subject, I really do.

I know the logics of the following are wrong, but if i beat my head 10x on the wall nothing will change.

I had already done this before I came here, but still didnt find no solution.

Right, lets get to the point. If I want to make an "unordened" list, let the computer decide. What I thought of:

Code: [ Select ]
<input type=hidden name=q value="<?php 
mt_srand(time());
$counter = mt_rand(0,5);
switch($counter) {
case 0: echo $answer[0]; break;
case 1: echo $answer[1]; break;
case 2: echo $answer[2]; break;
case 3: echo $answer[3]; break;
case 4: echo $answer[4]; break;
case 5: echo $answer[5]; break;
}
?>">
  1. <input type=hidden name=q value="<?php 
  2. mt_srand(time());
  3. $counter = mt_rand(0,5);
  4. switch($counter) {
  5. case 0: echo $answer[0]; break;
  6. case 1: echo $answer[1]; break;
  7. case 2: echo $answer[2]; break;
  8. case 3: echo $answer[3]; break;
  9. case 4: echo $answer[4]; break;
  10. case 5: echo $answer[5]; break;
  11. }
  12. ?>">


seems pretty logic, right?
Calculate the time in seconds from 1970 and calculate in a way that the outcome will be 0,1,2,3,4,5

Sorry if im slowing you down, I wasnt sure if itd come familiar to you.

I think that works fine.

The problem is, saving it.
For displaying it I used

Code: [ Select ]
<?php 
echo $q;
?>
  1. <?php 
  2. echo $q;
  3. ?>


But thats wrong, right?
If I do that, itll calculate again and probably come to another number.

Code: [ Select ]
<?php
$Qword[] = "offered";
$Qword[] = "don/'t match";
$Qword[] = "whether or";
$Qword[] = "regulations";
$Qword[] = "portfolio";

$answer[] = "medewerkers";
$answer[] = "boden aan";
$answer[] = "passen niet bij elkaar";
$answer[] = "of of";
$answer[] = "regels";

// set $number/$correct/$incorrect to zero if it isn't already set or is too high

if(!isset($number))
{
  $number=0;
}

if(!isset($correct))
{
  $correct=0;
}

if(!isset($incorrect))
{
  $incorrect=0;
}
?>
  1. <?php
  2. $Qword[] = "offered";
  3. $Qword[] = "don/'t match";
  4. $Qword[] = "whether or";
  5. $Qword[] = "regulations";
  6. $Qword[] = "portfolio";
  7. $answer[] = "medewerkers";
  8. $answer[] = "boden aan";
  9. $answer[] = "passen niet bij elkaar";
  10. $answer[] = "of of";
  11. $answer[] = "regels";
  12. // set $number/$correct/$incorrect to zero if it isn't already set or is too high
  13. if(!isset($number))
  14. {
  15.   $number=0;
  16. }
  17. if(!isset($correct))
  18. {
  19.   $correct=0;
  20. }
  21. if(!isset($incorrect))
  22. {
  23.   $incorrect=0;
  24. }
  25. ?>


the header is the usual ^^
I kept the $number variable for counting how much words you have translated. The correct and incorrect count how much correct/incorrect translated. These things work fine.

//Note: I switched $Qword for $answer, so the question will hold $answer, and the answer will hold $Qword

Code: [ Select ]
<input type=hidden name=canswer value="<?php
switch($q) {
case 0: echo $Qword[0]; break;
case 1: echo $Qword[1]; break;
case 2: echo $Qword[2]; break;
case 3: echo $Qword[3]; break;
case 4: echo $Qword[4]; break;
case 5: echo $Qword[5]; break;
}
// increment number by one (same as $number = $number + 1)
$number++;
?>
  1. <input type=hidden name=canswer value="<?php
  2. switch($q) {
  3. case 0: echo $Qword[0]; break;
  4. case 1: echo $Qword[1]; break;
  5. case 2: echo $Qword[2]; break;
  6. case 3: echo $Qword[3]; break;
  7. case 4: echo $Qword[4]; break;
  8. case 5: echo $Qword[5]; break;
  9. }
  10. // increment number by one (same as $number = $number + 1)
  11. $number++;
  12. ?>


I used this for getting the right answer.
But ofcourse this is wrong again, because it would get a new number again, right?

for sending the info i have

Code: [ Select ]
<input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
<input type="hidden" name="number" value="<? echo $number ?>">
<input type="hidden" name="correct" value="<? echo $correct ?>">
<input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
  1. <input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  2. <input type="hidden" name="number" value="<? echo $number ?>">
  3. <input type="hidden" name="correct" value="<? echo $correct ?>">
  4. <input type="hidden" name="incorrect" value="<? echo $incorrect ?>">


__________________-
Evaluation

Code: [ Select ]
<?php
if($fillin != $canswer){
// answer is incorrect
echo "Fout!";
$incorrect++;
} else {
// answer is correct
echo "Goed!";
$correct++;
}
?>
  1. <?php
  2. if($fillin != $canswer){
  3. // answer is incorrect
  4. echo "Fout!";
  5. $incorrect++;
  6. } else {
  7. // answer is correct
  8. echo "Goed!";
  9. $correct++;
  10. }
  11. ?>


For displaying wrong/right, and calculating wrong/right.

Code: [ Select ]
<form name="Volgende" action="unordened.php" method="post">
<input type="submit" name="next" value="Volgende" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
<input type="hidden" name="number" value="<? echo $number ?>">
<input type="hidden" name="correct" value="<? echo $correct ?>">
<input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
</form>
  1. <form name="Volgende" action="unordened.php" method="post">
  2. <input type="submit" name="next" value="Volgende" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  3. <input type="hidden" name="number" value="<? echo $number ?>">
  4. <input type="hidden" name="correct" value="<? echo $correct ?>">
  5. <input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
  6. </form>


Sending back the info....

And some other, like showing amount of incorrect/correct/total done, your answer, the correct answer.
But I doubt those will be of any matter here.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I just realized that your switch statements are redundant and not necessary. I should have noticed it before, but I was just quickly looking at the other stuff. I edited my post above to show it without the switch statement.

I'll look into the random thing shortly - generating a random value instead of incrementing should be no big deal, but you will want to keep track of which words you have already asked, so that it doesn't keep asking the same words over and over again. I think you can do this by using a string to hold the number values of the words that have been asked so far. I'm not all that familiar with php's string handling functions, but I will look into it.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Ok, if I understood correctly you were looking to ask the Qwords in random order, so I generated the random number the same way you did and kept track of the numbers used so far by adding (concatenating) them to a string of digits. I passed the $asked string back and forth as a hidden value in the same manner you're already using.

Then, each time I generated a new random number I checked first to see if all the words had been using by comparing the number of digits in the $asked string to the total number of words in the Qwords array. If all the words hadn't been used yet, I next checked to see if the new random number was a Qword that hadn't been asked yet by checking to see if it was already one of the digits in the $asked string. If it was, I kept generating a new random number until I found one that hadn't been used already.

If all the Qwords had been asked I showed the results and exited the script with a link back to the page to start over again. If the user clicks the link then they request the page again without any hidden values set and everything is initialized again and the process begins anew.

ordened.php
Code: [ Select ]
<?php

$Qword[0] = "sketch";
$Qword[1] = "regulations";
$Qword[2] = "excellent";
$Qword[3] = "staff";
$Qword[4] = "drawings";
$Qword[5] = "portfolio";

$answer[0] = "schets";
$answer[1] = "regels";
$answer[2] = "geweldig";
$answer[3] = "medewerkers";
$answer[4] = "tekeningen";
$answer[5] = "verzamelmap";

mt_srand(time());
$randomNum = mt_rand(0,5);

// if we haven't started yet initialize everything
if(!isset($number))
{
    $asked="$randomNum";
    $number=0;
    $correct=0;
    $incorrect=0;
}
else
{
    // if the number of words asked so far is less than the total number
    // of Qwords keep choosing randomly until every Qword is used once

    if(strlen($asked) < count($Qword))
    {
        // while the randomNum is found in the asked string
        // keep looking for one that hasn't been asked yet

        while(substr_count($asked,$randomNum)!=0)
        {
            $randomNum = mt_rand(0,5);    
        }

        // add the next value to the asked string
        $asked.="$randomNum";        
    }
    else
    {
        // all the Qwords have been asked if we're here
        echo "<p>All Done!</p>";
        echo "<p>Words asked: $number </p>";
        echo "<p>Correct answers: $correct </p>";
        echo "<p>Incorrect answers: $incorrect </p>";
        echo "<p>To try again <a href=\"ordened.php\">Click Here</a></p>";
        exit;        
    }
}
$number++;
?>

<form name="ordened" action="evaluation2.php" method="post">
<?php echo $Qword[$randomNum] ?>
<input type=text name=fillin size="60">
<input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
<input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
<input type="hidden" name="asked" value="<?php echo $asked ?>">
<input type="hidden" name="number" value="<? echo $number ?>">
<input type="hidden" name="correct" value="<? echo $correct ?>">
<input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
<input type="submit" name="invullen" value="Invullen" size=10 >
</form>

<script type="text/javascript">
<!--
document.ordened.fillin.focus();
-->
</script>
  1. <?php
  2. $Qword[0] = "sketch";
  3. $Qword[1] = "regulations";
  4. $Qword[2] = "excellent";
  5. $Qword[3] = "staff";
  6. $Qword[4] = "drawings";
  7. $Qword[5] = "portfolio";
  8. $answer[0] = "schets";
  9. $answer[1] = "regels";
  10. $answer[2] = "geweldig";
  11. $answer[3] = "medewerkers";
  12. $answer[4] = "tekeningen";
  13. $answer[5] = "verzamelmap";
  14. mt_srand(time());
  15. $randomNum = mt_rand(0,5);
  16. // if we haven't started yet initialize everything
  17. if(!isset($number))
  18. {
  19.     $asked="$randomNum";
  20.     $number=0;
  21.     $correct=0;
  22.     $incorrect=0;
  23. }
  24. else
  25. {
  26.     // if the number of words asked so far is less than the total number
  27.     // of Qwords keep choosing randomly until every Qword is used once
  28.     if(strlen($asked) < count($Qword))
  29.     {
  30.         // while the randomNum is found in the asked string
  31.         // keep looking for one that hasn't been asked yet
  32.         while(substr_count($asked,$randomNum)!=0)
  33.         {
  34.             $randomNum = mt_rand(0,5);    
  35.         }
  36.         // add the next value to the asked string
  37.         $asked.="$randomNum";        
  38.     }
  39.     else
  40.     {
  41.         // all the Qwords have been asked if we're here
  42.         echo "<p>All Done!</p>";
  43.         echo "<p>Words asked: $number </p>";
  44.         echo "<p>Correct answers: $correct </p>";
  45.         echo "<p>Incorrect answers: $incorrect </p>";
  46.         echo "<p>To try again <a href=\"ordened.php\">Click Here</a></p>";
  47.         exit;        
  48.     }
  49. }
  50. $number++;
  51. ?>
  52. <form name="ordened" action="evaluation2.php" method="post">
  53. <?php echo $Qword[$randomNum] ?>
  54. <input type=text name=fillin size="60">
  55. <input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
  56. <input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
  57. <input type="hidden" name="asked" value="<?php echo $asked ?>">
  58. <input type="hidden" name="number" value="<? echo $number ?>">
  59. <input type="hidden" name="correct" value="<? echo $correct ?>">
  60. <input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
  61. <input type="submit" name="invullen" value="Invullen" size=10 >
  62. </form>
  63. <script type="text/javascript">
  64. <!--
  65. document.ordened.fillin.focus();
  66. -->
  67. </script>


evaluation2.php
Code: [ Select ]
<?php
if($fillin != $canswer){
// answer is incorrect
echo "Fout!";
$incorrect++;
} else {
// answer is correct
echo "Goed!";
$correct++;
}
?>

<form name="Volgende" action="ordened.php" method="post">
<input type="submit" name="next" value="Volgende" size=10 >
<input type="hidden" name="number" value="<? echo $number ?>">
<input type="hidden" name="correct" value="<? echo $correct ?>">
<input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
<input type="hidden" name="asked" value="<? echo $asked ?>">
</form>

<p>The word: <?php echo $q ?></p>
<p>Your answer: <?php echo $fillin ?></p>
<p>Correct answer: <?php echo $canswer ?></p>
<p>Total asked so far: <?php echo $number ?></p>
<p>Correct answers so far: <?php echo $correct ?></p> 
<p>Incorrect answers so far: <?php echo $incorrect ?></p>

<script type="text/javascript">
<!--
document.Volgende.next.focus();
-->
</script>
  1. <?php
  2. if($fillin != $canswer){
  3. // answer is incorrect
  4. echo "Fout!";
  5. $incorrect++;
  6. } else {
  7. // answer is correct
  8. echo "Goed!";
  9. $correct++;
  10. }
  11. ?>
  12. <form name="Volgende" action="ordened.php" method="post">
  13. <input type="submit" name="next" value="Volgende" size=10 >
  14. <input type="hidden" name="number" value="<? echo $number ?>">
  15. <input type="hidden" name="correct" value="<? echo $correct ?>">
  16. <input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
  17. <input type="hidden" name="asked" value="<? echo $asked ?>">
  18. </form>
  19. <p>The word: <?php echo $q ?></p>
  20. <p>Your answer: <?php echo $fillin ?></p>
  21. <p>Correct answer: <?php echo $canswer ?></p>
  22. <p>Total asked so far: <?php echo $number ?></p>
  23. <p>Correct answers so far: <?php echo $correct ?></p> 
  24. <p>Incorrect answers so far: <?php echo $incorrect ?></p>
  25. <script type="text/javascript">
  26. <!--
  27. document.Volgende.next.focus();
  28. -->
  29. </script>

[code]
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

thanks man, i dont think i wouldve figured it that out.

Theres this last thing, a command that i dont know, but that has to exist.

as the final result im currently using

Code: [ Select ]
<?php
if($number == 114){

$percentagec = $correct / $number * 100;
$percentagei = $incorrect / $number * 100;


if(strlen($percentagec) > 3){
$pcorrect = substr($percentagec,0,4);
}

if(strlen($percentagei) > 3){
$pincorrect = substr($percentagei,0,4);
}

echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
echo $incorrect." fout,<br>";
echo "van de ".$number." vragen.";
echo "<p>U had ongeveer ".$pcorrect."% goed, en ".$pincorrect."% fout.</span></font>";
}
else
{
?>
.....
<?php
}
?>
  1. <?php
  2. if($number == 114){
  3. $percentagec = $correct / $number * 100;
  4. $percentagei = $incorrect / $number * 100;
  5. if(strlen($percentagec) > 3){
  6. $pcorrect = substr($percentagec,0,4);
  7. }
  8. if(strlen($percentagei) > 3){
  9. $pincorrect = substr($percentagei,0,4);
  10. }
  11. echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
  12. echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
  13. echo $incorrect." fout,<br>";
  14. echo "van de ".$number." vragen.";
  15. echo "<p>U had ongeveer ".$pcorrect."% goed, en ".$pincorrect."% fout.</span></font>";
  16. }
  17. else
  18. {
  19. ?>
  20. .....
  21. <?php
  22. }
  23. ?>


Basically, its about the % correct/incorrect
i made it so that if it has more then 3 digits, only display the first 3.
But, this wont always be completely right, cause it should be rounded off.
For example, it could show 85% correct, and 14,9$ wrong.

Im not aware of the command/function, its not written in the book I own, and some other people i know couldnt tell me either. They did agree that it should exist though.
Do you, or any other, happen to know it?
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I think the round() funtion should be what you are looking for - if you look at the example in the php manual by clicking the link, I think it will kill two birds with one stone by rounding off and setting the precision.

Two other useful rounding functions are ceil() and floor().
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

thanks a million. im sure it will do.
  • Inito
  • Graduate
  • Graduate
  • User avatar
  • Posts: 223

Post 3+ Months Ago

actually, I just figured it doesnt.
maybe its me, but it always picks another answer at the evaluation. (as if $randomNum is calculated again.

http://members.lycos.nl/dave90/over/ordened.php


heres the full code, not just the php (although thats the biggest part):

Code: [ Select ]
<body bgcolor="#999999" text="#000000">

<?php
$Qword[] = "offered";
$Qword[] = "don/'t match";
$Qword[] = "whether or";
$Qword[] = "regulations";
$Qword[] = "portfolio";
$Qword[] = "background";
$Qword[] = "sentimental";
$Qword[] = "sketch";
$Qword[] = "don't get too big for your boots";
$Qword[] = "design";
$Qword[] = "excellent";
$Qword[] = "surprised";
$Qword[] = "especially";
$Qword[] = "allowed";
$Qword[] = "drawings";
$Qword[] = "original";
$Qword[] = "evil";
$Qword[] = "see your point";
$Qword[] = "practice";
$Qword[] = "I was only joking";
$Qword[] = "tutor";
$Qword[] = "effort";
$Qword[] = "staff";
$Qword[] = "opportunity";
$Qword[] = "clay";
$Qword[] = "encouraged";
$Qword[] = "course";
$Qword[] = "drama";
$Qword[] = "experienced";
$Qword[] = "disability";
$Qword[] = "in cash";
$Qword[] = "imagination";
$Qword[] = "skill";
$Qword[] = "admitted";
$Qword[] = "guarantee";
$Qword[] = "was unable";
$Qword[] = "apparently";
$Qword[] = "victims";
$Qword[] = "heatwave";
$Qword[] = "fancy seeing her there!";
$Qword[] = "book";
$Qword[] = "actually";
$Qword[] = "anyway";
$Qword[] = "weight";
$Qword[] = "the weather changed";
$Qword[] = "what's the matter";
$Qword[] = "am bored stiff";
$Qword[] = "gossiping";
$Qword[] = "discover";
$Qword[] = "arrive";
$Qword[] = "convict";
$Qword[] = "poverty";
$Qword[] = "settled";
$Qword[] = "peace treaty";
$Qword[] = "trail";
$Qword[] = "discriminated against";
$Qword[] = "foster parents";
$Qword[] = "earn a living";
$Qword[] = "insult";
$Qword[] = "bowl";
$Qword[] = "way over the top";
$Qword[] = "once in a while";
$Qword[] = "treat";
$Qword[] = "'d rather not";
$Qword[] = "prefers";
$Qword[] = "you bet";
$Qword[] = "what on earth";
$Qword[] = "leaflet";
$Qword[] = "was sick";
$Qword[] = "walls";
$Qword[] = "give it a try";
$Qword[] = "get any ideas";
$Qword[] = "favourite";
$Qword[] = "pro";
$Qword[] = "performance";
$Qword[] = "equipped";
$Qword[] = "raise";
$Qword[] = "summit";
$Qword[] = "despite";
$Qword[] = "elementary school";
$Qword[] = "injury";
$Qword[] = "afford";
$Qword[] = "inner city";
$Qword[] = "seal";
$Qword[] = "nursed";
$Qword[] = "prepare";
$Qword[] = "hunted";
$Qword[] = "skate";
$Qword[] = "depends";
$Qword[] = "compete";
$Qword[] = "mistake";
$Qword[] = "courage";
$Qword[] = "certain";
$Qword[] = "recycle";
$Qword[] = "travelling";
$Qword[] = "volunteer";
$Qword[] = "solar system";
$Qword[] = "adventure";
$Qword[] = "made me feel sick";
$Qword[] = "Stone Age";
$Qword[] = "twice";
$Qword[] = "recognise";
$Qword[] = "instead of";
$Qword[] = "smell";
$Qword[] = "by the way";
$Qword[] = "interesting";
$Qword[] = "backpackers";
$Qword[] = "journey";
$Qword[] = "excited";
$Qword[] = "remain";
$Qword[] = "chatting";
$Qword[] = "adventure";
$Qword[] = "campsite";
$Qword[] = "brush your teeth";
$Qword[] = "noises";


$answer[] = "medewerkers";
$answer[] = "boden aan";
$answer[] = "passen niet bij elkaar";
$answer[] = "of of";
$answer[] = "regels";
$answer[] = "verzamelmap";
$answer[] = "herkomst";
$answer[] = "sentimenteel";
$answer[] = "schets";
$answer[] = "ga niet naast je schoenen lopen";
$answer[] = "ontwerp";
$answer[] = "geweldig";
$answer[] = "verbaasd";
$answer[] = "vooral";
$answer[] = "toegestaan";
$answer[] = "tekeningen";
$answer[] = "origineel";
$answer[] = "kwaad";
$answer[] = "snap wat je bedoelt";
$answer[] = "oefening";
$answer[] = "ik maakte maar een grapje";
$answer[] = "(privé)leraar";
$answer[] = "moeite, energie";
$answer[] = "medewerkers";
$answer[] = "gelegenheid, kans";
$answer[] = "klei";
$answer[] = "aangemoedigd";
$answer[] = "cursus";
$answer[] = "toneel";
$answer[] = "ervaren";
$answer[] = "handicap";
$answer[] = "contant";
$answer[] = "fantasie";
$answer[] = "vaardigheid";
$answer[] = "toegelaten";
$answer[] = "garantie";
$answer[] = "was niet in staat";
$answer[] = "blijkbaar";
$answer[] = "slachtoffers";
$answer[] = "hittegolf";
$answer[] = "wie had gedacht dat ik haar daar zou zien";
$answer[] = "boeken";
$answer[] = "eigenlijk, in feite";
$answer[] = "hoe dan ook, enfin";
$answer[] = "gewicht";
$answer[] = "het weer sloeg om";
$answer[] = "wat is er aan de hand";
$answer[] = "verveel me stierlijk";
$answer[] = "roddelen";
$answer[] = "ontdekken";
$answer[] = "veroordeelde, gevangene";
$answer[] = "armoede";
$answer[] = "zich vestigden";
$answer[] = "vredesverdrag";
$answer[] = "spoor";
$answer[] = "gediscrimineerd";
$answer[] = "pleegouders";
$answer[] = "kost verdienen";
$answer[] = "belediging";
$answer[] = "kom";
$answer[] = "te oud";
$answer[] = "zo nu en dan";
$answer[] = "traktatie";
$answer[] = "wil liever niet";
$answer[] = "wil liever";
$answer[] = "zeker weten";
$answer[] = "in 's hemelsnaam";
$answer[] = "folder";
$answer[] = "gaf over";
$answer[] = "muren";
$answer[] = "probeer het eens";
$answer[] = "rare ideeën krijgen";
$answer[] = "favoriet";
$answer[] = "prof";
$answer[] = "optreden";
$answer[] = "uitgerust met";
$answer[] = "bijeenbrengen";
$answer[] = "top";
$answer[] = "ondanks";
$answer[] = "basischool";
$answer[] = "verwonding";
$answer[] = "veroorloven";
$answer[] = "binnenstad";
$answer[] = "zeehond";
$answer[] = "verpleegde";
$answer[] = "klaarmaken";
$answer[] = "(op)gejaagd";
$answer[] = "schaatsen";
$answer[] = "besteedt";
$answer[] = "meedoen";
$answer[] = "fout";
$answer[] = "moed";
$answer[] = "zeker";
$answer[] = "hergebruiken";
$answer[] = "reizen";
$answer[] = "vrijwilliger";
$answer[] = "zonnenstelsel";
$answer[] = "avonturen-";
$answer[] = "maakte me misselijk";
$answer[] = "stenen tijdperk";
$answer[] = "twee keer";
$answer[] = "herkennen";
$answer[] = "in plaats van";
$answer[] = "geur, stank";
$answer[] = "trouwens";
$answer[] = "interessant";
$answer[] = "rugzaktoeristen";
$answer[] = "reis";
$answer[] = "opgewonden";
$answer[] = "blijf";
$answer[] = "kletsen";
$answer[] = "avontuur";
$answer[] = "camping";
$answer[] = "poets je tanden";
$answer[] = "geluiden";

mt_srand(time());
$randomNum = mt_rand(0,5);

// if we haven't started yet initialize everything
if(!isset($number))
{
  $asked="$randomNum";
  $number=0;
  $correct=0;
  $incorrect=0;
}
else
{
  // if the number of words asked so far is less than the total number
  // of Qwords keep choosing randomly until every Qword is used once

  if(strlen($asked) < count($Qword))
  {
   // while the randomNum is found in the asked string
   // keep looking for one that hasn't been asked yet

   while(substr_count($asked,$randomNum)!=0)
   {
     $randomNum = mt_rand(0,5);  
   }

   // add the next value to the asked string
   $asked.="$randomNum";   
  }
  else 
   {

$percentagec = $correct / $number * 100;
$percentagei = $incorrect / $number * 100;


if(strlen($percentagec) > 3){
$pcorrect = substr($percentagec,0,4);
}

if(strlen($percentagei) > 3){
$pincorrect = substr($percentagei,0,4);
}

echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
echo $incorrect." fout,<br>";
echo "van de ".$number." vragen.";
echo "<p>U had ongeveer ".$pcorrect."% goed, en ".$pincorrect."% fout.</span></font>";
exit;
  }
}
$number++;
?>


<p><br>
<p><br>
<center>

<form name="unordened" action="evaluation.php" method="post">
<table border="0" width="20%">
<tr>
<td>
<center>
<font face="arial"><span style="font-size:13">
Vertaal het volgende:
</span></font>
<p>
</center>
</td>
</tr>
<tr>
<td>
<center>
<font face="verdana" color="white"><span style="font-size:15"><span style="background-color: #000000">
<b>
&nbsp;
<?php echo $Qword[$randomNum] ?>
&nbsp;
</b>
</span></span></font>
</center>
<P>
</td>
</tr><tr>
<td>
<center>
<input type=text name=fillin size="60" style="BORDER: #000000 1px line ; FONT-SIZE: 12; FONT-FAMILY: Arial; LEFT: 0px; COLOR: black; HEIGHT: 1 8px; BACKGROUND-COLOR: #cccccc">
</center>
</td>
</tr><tr>
<td>
<center>
<p><br>
<input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
<input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
<input type="hidden" name="asked" value="<?php echo $asked ?>">
<input type="hidden" name="number" value="<? echo $number ?>">
<input type="hidden" name="correct" value="<? echo $correct ?>">
<input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
<input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
</center>
</td>
</tr>
</table>
</form>

<script type="text/javascript">
<!--
document.unordened.fillin.focus();
-->
</script>

</center>
  1. <body bgcolor="#999999" text="#000000">
  2. <?php
  3. $Qword[] = "offered";
  4. $Qword[] = "don/'t match";
  5. $Qword[] = "whether or";
  6. $Qword[] = "regulations";
  7. $Qword[] = "portfolio";
  8. $Qword[] = "background";
  9. $Qword[] = "sentimental";
  10. $Qword[] = "sketch";
  11. $Qword[] = "don't get too big for your boots";
  12. $Qword[] = "design";
  13. $Qword[] = "excellent";
  14. $Qword[] = "surprised";
  15. $Qword[] = "especially";
  16. $Qword[] = "allowed";
  17. $Qword[] = "drawings";
  18. $Qword[] = "original";
  19. $Qword[] = "evil";
  20. $Qword[] = "see your point";
  21. $Qword[] = "practice";
  22. $Qword[] = "I was only joking";
  23. $Qword[] = "tutor";
  24. $Qword[] = "effort";
  25. $Qword[] = "staff";
  26. $Qword[] = "opportunity";
  27. $Qword[] = "clay";
  28. $Qword[] = "encouraged";
  29. $Qword[] = "course";
  30. $Qword[] = "drama";
  31. $Qword[] = "experienced";
  32. $Qword[] = "disability";
  33. $Qword[] = "in cash";
  34. $Qword[] = "imagination";
  35. $Qword[] = "skill";
  36. $Qword[] = "admitted";
  37. $Qword[] = "guarantee";
  38. $Qword[] = "was unable";
  39. $Qword[] = "apparently";
  40. $Qword[] = "victims";
  41. $Qword[] = "heatwave";
  42. $Qword[] = "fancy seeing her there!";
  43. $Qword[] = "book";
  44. $Qword[] = "actually";
  45. $Qword[] = "anyway";
  46. $Qword[] = "weight";
  47. $Qword[] = "the weather changed";
  48. $Qword[] = "what's the matter";
  49. $Qword[] = "am bored stiff";
  50. $Qword[] = "gossiping";
  51. $Qword[] = "discover";
  52. $Qword[] = "arrive";
  53. $Qword[] = "convict";
  54. $Qword[] = "poverty";
  55. $Qword[] = "settled";
  56. $Qword[] = "peace treaty";
  57. $Qword[] = "trail";
  58. $Qword[] = "discriminated against";
  59. $Qword[] = "foster parents";
  60. $Qword[] = "earn a living";
  61. $Qword[] = "insult";
  62. $Qword[] = "bowl";
  63. $Qword[] = "way over the top";
  64. $Qword[] = "once in a while";
  65. $Qword[] = "treat";
  66. $Qword[] = "'d rather not";
  67. $Qword[] = "prefers";
  68. $Qword[] = "you bet";
  69. $Qword[] = "what on earth";
  70. $Qword[] = "leaflet";
  71. $Qword[] = "was sick";
  72. $Qword[] = "walls";
  73. $Qword[] = "give it a try";
  74. $Qword[] = "get any ideas";
  75. $Qword[] = "favourite";
  76. $Qword[] = "pro";
  77. $Qword[] = "performance";
  78. $Qword[] = "equipped";
  79. $Qword[] = "raise";
  80. $Qword[] = "summit";
  81. $Qword[] = "despite";
  82. $Qword[] = "elementary school";
  83. $Qword[] = "injury";
  84. $Qword[] = "afford";
  85. $Qword[] = "inner city";
  86. $Qword[] = "seal";
  87. $Qword[] = "nursed";
  88. $Qword[] = "prepare";
  89. $Qword[] = "hunted";
  90. $Qword[] = "skate";
  91. $Qword[] = "depends";
  92. $Qword[] = "compete";
  93. $Qword[] = "mistake";
  94. $Qword[] = "courage";
  95. $Qword[] = "certain";
  96. $Qword[] = "recycle";
  97. $Qword[] = "travelling";
  98. $Qword[] = "volunteer";
  99. $Qword[] = "solar system";
  100. $Qword[] = "adventure";
  101. $Qword[] = "made me feel sick";
  102. $Qword[] = "Stone Age";
  103. $Qword[] = "twice";
  104. $Qword[] = "recognise";
  105. $Qword[] = "instead of";
  106. $Qword[] = "smell";
  107. $Qword[] = "by the way";
  108. $Qword[] = "interesting";
  109. $Qword[] = "backpackers";
  110. $Qword[] = "journey";
  111. $Qword[] = "excited";
  112. $Qword[] = "remain";
  113. $Qword[] = "chatting";
  114. $Qword[] = "adventure";
  115. $Qword[] = "campsite";
  116. $Qword[] = "brush your teeth";
  117. $Qword[] = "noises";
  118. $answer[] = "medewerkers";
  119. $answer[] = "boden aan";
  120. $answer[] = "passen niet bij elkaar";
  121. $answer[] = "of of";
  122. $answer[] = "regels";
  123. $answer[] = "verzamelmap";
  124. $answer[] = "herkomst";
  125. $answer[] = "sentimenteel";
  126. $answer[] = "schets";
  127. $answer[] = "ga niet naast je schoenen lopen";
  128. $answer[] = "ontwerp";
  129. $answer[] = "geweldig";
  130. $answer[] = "verbaasd";
  131. $answer[] = "vooral";
  132. $answer[] = "toegestaan";
  133. $answer[] = "tekeningen";
  134. $answer[] = "origineel";
  135. $answer[] = "kwaad";
  136. $answer[] = "snap wat je bedoelt";
  137. $answer[] = "oefening";
  138. $answer[] = "ik maakte maar een grapje";
  139. $answer[] = "(privé)leraar";
  140. $answer[] = "moeite, energie";
  141. $answer[] = "medewerkers";
  142. $answer[] = "gelegenheid, kans";
  143. $answer[] = "klei";
  144. $answer[] = "aangemoedigd";
  145. $answer[] = "cursus";
  146. $answer[] = "toneel";
  147. $answer[] = "ervaren";
  148. $answer[] = "handicap";
  149. $answer[] = "contant";
  150. $answer[] = "fantasie";
  151. $answer[] = "vaardigheid";
  152. $answer[] = "toegelaten";
  153. $answer[] = "garantie";
  154. $answer[] = "was niet in staat";
  155. $answer[] = "blijkbaar";
  156. $answer[] = "slachtoffers";
  157. $answer[] = "hittegolf";
  158. $answer[] = "wie had gedacht dat ik haar daar zou zien";
  159. $answer[] = "boeken";
  160. $answer[] = "eigenlijk, in feite";
  161. $answer[] = "hoe dan ook, enfin";
  162. $answer[] = "gewicht";
  163. $answer[] = "het weer sloeg om";
  164. $answer[] = "wat is er aan de hand";
  165. $answer[] = "verveel me stierlijk";
  166. $answer[] = "roddelen";
  167. $answer[] = "ontdekken";
  168. $answer[] = "veroordeelde, gevangene";
  169. $answer[] = "armoede";
  170. $answer[] = "zich vestigden";
  171. $answer[] = "vredesverdrag";
  172. $answer[] = "spoor";
  173. $answer[] = "gediscrimineerd";
  174. $answer[] = "pleegouders";
  175. $answer[] = "kost verdienen";
  176. $answer[] = "belediging";
  177. $answer[] = "kom";
  178. $answer[] = "te oud";
  179. $answer[] = "zo nu en dan";
  180. $answer[] = "traktatie";
  181. $answer[] = "wil liever niet";
  182. $answer[] = "wil liever";
  183. $answer[] = "zeker weten";
  184. $answer[] = "in 's hemelsnaam";
  185. $answer[] = "folder";
  186. $answer[] = "gaf over";
  187. $answer[] = "muren";
  188. $answer[] = "probeer het eens";
  189. $answer[] = "rare ideeën krijgen";
  190. $answer[] = "favoriet";
  191. $answer[] = "prof";
  192. $answer[] = "optreden";
  193. $answer[] = "uitgerust met";
  194. $answer[] = "bijeenbrengen";
  195. $answer[] = "top";
  196. $answer[] = "ondanks";
  197. $answer[] = "basischool";
  198. $answer[] = "verwonding";
  199. $answer[] = "veroorloven";
  200. $answer[] = "binnenstad";
  201. $answer[] = "zeehond";
  202. $answer[] = "verpleegde";
  203. $answer[] = "klaarmaken";
  204. $answer[] = "(op)gejaagd";
  205. $answer[] = "schaatsen";
  206. $answer[] = "besteedt";
  207. $answer[] = "meedoen";
  208. $answer[] = "fout";
  209. $answer[] = "moed";
  210. $answer[] = "zeker";
  211. $answer[] = "hergebruiken";
  212. $answer[] = "reizen";
  213. $answer[] = "vrijwilliger";
  214. $answer[] = "zonnenstelsel";
  215. $answer[] = "avonturen-";
  216. $answer[] = "maakte me misselijk";
  217. $answer[] = "stenen tijdperk";
  218. $answer[] = "twee keer";
  219. $answer[] = "herkennen";
  220. $answer[] = "in plaats van";
  221. $answer[] = "geur, stank";
  222. $answer[] = "trouwens";
  223. $answer[] = "interessant";
  224. $answer[] = "rugzaktoeristen";
  225. $answer[] = "reis";
  226. $answer[] = "opgewonden";
  227. $answer[] = "blijf";
  228. $answer[] = "kletsen";
  229. $answer[] = "avontuur";
  230. $answer[] = "camping";
  231. $answer[] = "poets je tanden";
  232. $answer[] = "geluiden";
  233. mt_srand(time());
  234. $randomNum = mt_rand(0,5);
  235. // if we haven't started yet initialize everything
  236. if(!isset($number))
  237. {
  238.   $asked="$randomNum";
  239.   $number=0;
  240.   $correct=0;
  241.   $incorrect=0;
  242. }
  243. else
  244. {
  245.   // if the number of words asked so far is less than the total number
  246.   // of Qwords keep choosing randomly until every Qword is used once
  247.   if(strlen($asked) < count($Qword))
  248.   {
  249.    // while the randomNum is found in the asked string
  250.    // keep looking for one that hasn't been asked yet
  251.    while(substr_count($asked,$randomNum)!=0)
  252.    {
  253.      $randomNum = mt_rand(0,5);  
  254.    }
  255.    // add the next value to the asked string
  256.    $asked.="$randomNum";   
  257.   }
  258.   else 
  259.    {
  260. $percentagec = $correct / $number * 100;
  261. $percentagei = $incorrect / $number * 100;
  262. if(strlen($percentagec) > 3){
  263. $pcorrect = substr($percentagec,0,4);
  264. }
  265. if(strlen($percentagei) > 3){
  266. $pincorrect = substr($percentagei,0,4);
  267. }
  268. echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
  269. echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
  270. echo $incorrect." fout,<br>";
  271. echo "van de ".$number." vragen.";
  272. echo "<p>U had ongeveer ".$pcorrect."% goed, en ".$pincorrect."% fout.</span></font>";
  273. exit;
  274.   }
  275. }
  276. $number++;
  277. ?>
  278. <p><br>
  279. <p><br>
  280. <center>
  281. <form name="unordened" action="evaluation.php" method="post">
  282. <table border="0" width="20%">
  283. <tr>
  284. <td>
  285. <center>
  286. <font face="arial"><span style="font-size:13">
  287. Vertaal het volgende:
  288. </span></font>
  289. <p>
  290. </center>
  291. </td>
  292. </tr>
  293. <tr>
  294. <td>
  295. <center>
  296. <font face="verdana" color="white"><span style="font-size:15"><span style="background-color: #000000">
  297. <b>
  298. &nbsp;
  299. <?php echo $Qword[$randomNum] ?>
  300. &nbsp;
  301. </b>
  302. </span></span></font>
  303. </center>
  304. <P>
  305. </td>
  306. </tr><tr>
  307. <td>
  308. <center>
  309. <input type=text name=fillin size="60" style="BORDER: #000000 1px line ; FONT-SIZE: 12; FONT-FAMILY: Arial; LEFT: 0px; COLOR: black; HEIGHT: 1 8px; BACKGROUND-COLOR: #cccccc">
  310. </center>
  311. </td>
  312. </tr><tr>
  313. <td>
  314. <center>
  315. <p><br>
  316. <input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
  317. <input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
  318. <input type="hidden" name="asked" value="<?php echo $asked ?>">
  319. <input type="hidden" name="number" value="<? echo $number ?>">
  320. <input type="hidden" name="correct" value="<? echo $correct ?>">
  321. <input type="hidden" name="incorrect" value="<? echo $incorrect ?>">
  322. <input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  323. </center>
  324. </td>
  325. </tr>
  326. </table>
  327. </form>
  328. <script type="text/javascript">
  329. <!--
  330. document.unordened.fillin.focus();
  331. -->
  332. </script>
  333. </center>
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Those arrays have to be perfectly parallel for this to work. In other words if regels means regulations then they have to be in the same place in the corresponding arrays. Right now regulations is the fourth word in the Qword array, but regels is the fifth in the answer array. I'm a little bit handicapped by not understanding the language, but they don't look parallel to me.

I'll need to look at it a little bit more later when I have more time, but it won't work unless the arrays are perfectly parallel.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Ok, here's an example using 20 words and answers. I made a few changes: I used the round() function to determine the percent, I changed the way the asked variable was storing the numbers by adding spaces around the number so that "10" would be stored as " 10 " and then searched it looking for the number surrounded by spaces so that it wouldn't mistake 10 for 1 or 0, and I set the upper limit of the random generator as count($Qword-1) so that it will change automatically as you edit the list. Since arrays start counting from 0, an array with 20 strings will have the first element as 0 and the last as 19. In other words the last word in the array will be one less than the total number returned by count() since arrays start from 0 and not 1.

You will still need to edit these arrays to make them parallel. I can't because I don't know the language, but I'm pretty sure they don't match correctly. The first word in the answer array must be the correct translation for the first word in the Qwords array and so on.

Code: [ Select ]
<body bgcolor="#999999" text="#000000">
<?php
$Qword[] = "offered";
$Qword[] = "don't match";
$Qword[] = "whether or";
$Qword[] = "regulations";
$Qword[] = "portfolio";
$Qword[] = "background";
$Qword[] = "sentimental";
$Qword[] = "sketch";
$Qword[] = "don't get too big for your boots";
$Qword[] = "design";
$Qword[] = "excellent";
$Qword[] = "surprised";
$Qword[] = "especially";
$Qword[] = "allowed";
$Qword[] = "drawings";
$Qword[] = "original";
$Qword[] = "evil";
$Qword[] = "see your point";
$Qword[] = "practice";
$Qword[] = "I was only joking";

$answer[] = "medewerkers";
$answer[] = "boden aan";
$answer[] = "passen niet bij elkaar";
$answer[] = "of of";
$answer[] = "regels";
$answer[] = "verzamelmap";
$answer[] = "herkomst";
$answer[] = "sentimenteel";
$answer[] = "schets";
$answer[] = "ga niet naast je schoenen lopen";
$answer[] = "ontwerp";
$answer[] = "geweldig";
$answer[] = "verbaasd";
$answer[] = "vooral";
$answer[] = "toegestaan";
$answer[] = "tekeningen";
$answer[] = "origineel";
$answer[] = "kwaad";
$answer[] = "snap wat je bedoelt";
$answer[] = "oefening";

mt_srand(time());
$randomNum = mt_rand(0,count($Qword)-1);

// if we haven't started yet initialize everything
if(!isset($number))
{
  $asked=" $randomNum ";
  $number=0;
  $correct=0;
  $incorrect=0;
}
else
{
  // if the number of words asked so far is less than the total number
  // of Qwords keep choosing randomly until every Qword is used once

  if($number < count($Qword))
  {
   // while the randomNum is found in the asked string
   // keep looking for one that hasn't been asked yet

   while(substr_count($asked," $randomNum ")!=0)
   {
     $randomNum = mt_rand(0,count($Qword)-1); 
   }

   // add the next value to the asked string
   $asked.=" $randomNum ";   
  }
  else
    {
        $percentagec = round($correct / $number * 100, 0);
        $percentagei = round($incorrect / $number * 100, 0);
        echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
        echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
        echo $incorrect." fout,<br>";
        echo "van de ".$number." vragen.";
        echo "<p>U had ongeveer ".$percentagec."% goed, en ".$percentagei."% fout.</span></font>";
        exit;
    }
}
$number++;
?>


<p><br>
<p><br>
<center>

<form name="unordened" action="evaluation.php" method="post">
<table border="0" width="20%">
<tr>
<td>
<center>
<font face="arial"><span style="font-size:13">
Vertaal het volgende:
</span></font>
<p>
</center>
</td>
</tr>
<tr>
<td>
<center>
<font face="verdana" color="white"><span style="font-size:15"><span style="background-color: #000000">
<b>
&nbsp;
<?php echo $Qword[$randomNum] ?>
&nbsp;
</b>
</span></span></font>
</center>
<P>
</td>
</tr><tr>
<td>
<center>
<input type=text name=fillin size="60" style="BORDER: #000000 1px line ; FONT-SIZE: 12; FONT-FAMILY: Arial; LEFT: 0px; COLOR: black; HEIGHT: 1 8px; BACKGROUND-COLOR: #cccccc">
</center>
</td>
</tr><tr>
<td>
<center>
<p><br>
<input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
<input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
<input type="hidden" name="asked" value="<?php echo $asked ?>">
<input type="hidden" name="number" value="<?php echo $number ?>">
<input type="hidden" name="correct" value="<?php echo $correct ?>">
<input type="hidden" name="incorrect" value="<?php echo $incorrect ?>">
<input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
</center>
</td>
</tr>
</table>
</form>

<script type="text/javascript">
<!--
document.unordened.fillin.focus();
-->
</script>

</center>
  1. <body bgcolor="#999999" text="#000000">
  2. <?php
  3. $Qword[] = "offered";
  4. $Qword[] = "don't match";
  5. $Qword[] = "whether or";
  6. $Qword[] = "regulations";
  7. $Qword[] = "portfolio";
  8. $Qword[] = "background";
  9. $Qword[] = "sentimental";
  10. $Qword[] = "sketch";
  11. $Qword[] = "don't get too big for your boots";
  12. $Qword[] = "design";
  13. $Qword[] = "excellent";
  14. $Qword[] = "surprised";
  15. $Qword[] = "especially";
  16. $Qword[] = "allowed";
  17. $Qword[] = "drawings";
  18. $Qword[] = "original";
  19. $Qword[] = "evil";
  20. $Qword[] = "see your point";
  21. $Qword[] = "practice";
  22. $Qword[] = "I was only joking";
  23. $answer[] = "medewerkers";
  24. $answer[] = "boden aan";
  25. $answer[] = "passen niet bij elkaar";
  26. $answer[] = "of of";
  27. $answer[] = "regels";
  28. $answer[] = "verzamelmap";
  29. $answer[] = "herkomst";
  30. $answer[] = "sentimenteel";
  31. $answer[] = "schets";
  32. $answer[] = "ga niet naast je schoenen lopen";
  33. $answer[] = "ontwerp";
  34. $answer[] = "geweldig";
  35. $answer[] = "verbaasd";
  36. $answer[] = "vooral";
  37. $answer[] = "toegestaan";
  38. $answer[] = "tekeningen";
  39. $answer[] = "origineel";
  40. $answer[] = "kwaad";
  41. $answer[] = "snap wat je bedoelt";
  42. $answer[] = "oefening";
  43. mt_srand(time());
  44. $randomNum = mt_rand(0,count($Qword)-1);
  45. // if we haven't started yet initialize everything
  46. if(!isset($number))
  47. {
  48.   $asked=" $randomNum ";
  49.   $number=0;
  50.   $correct=0;
  51.   $incorrect=0;
  52. }
  53. else
  54. {
  55.   // if the number of words asked so far is less than the total number
  56.   // of Qwords keep choosing randomly until every Qword is used once
  57.   if($number < count($Qword))
  58.   {
  59.    // while the randomNum is found in the asked string
  60.    // keep looking for one that hasn't been asked yet
  61.    while(substr_count($asked," $randomNum ")!=0)
  62.    {
  63.      $randomNum = mt_rand(0,count($Qword)-1); 
  64.    }
  65.    // add the next value to the asked string
  66.    $asked.=" $randomNum ";   
  67.   }
  68.   else
  69.     {
  70.         $percentagec = round($correct / $number * 100, 0);
  71.         $percentagei = round($incorrect / $number * 100, 0);
  72.         echo "<font face=Arial><span style=font-size:14>Gefeliciteerd!<p>U bent klaar!</span></font>";
  73.         echo "<P><br><font face=Arial><span style=font-size:13>U had in totaal ".$correct." goed, ";
  74.         echo $incorrect." fout,<br>";
  75.         echo "van de ".$number." vragen.";
  76.         echo "<p>U had ongeveer ".$percentagec."% goed, en ".$percentagei."% fout.</span></font>";
  77.         exit;
  78.     }
  79. }
  80. $number++;
  81. ?>
  82. <p><br>
  83. <p><br>
  84. <center>
  85. <form name="unordened" action="evaluation.php" method="post">
  86. <table border="0" width="20%">
  87. <tr>
  88. <td>
  89. <center>
  90. <font face="arial"><span style="font-size:13">
  91. Vertaal het volgende:
  92. </span></font>
  93. <p>
  94. </center>
  95. </td>
  96. </tr>
  97. <tr>
  98. <td>
  99. <center>
  100. <font face="verdana" color="white"><span style="font-size:15"><span style="background-color: #000000">
  101. <b>
  102. &nbsp;
  103. <?php echo $Qword[$randomNum] ?>
  104. &nbsp;
  105. </b>
  106. </span></span></font>
  107. </center>
  108. <P>
  109. </td>
  110. </tr><tr>
  111. <td>
  112. <center>
  113. <input type=text name=fillin size="60" style="BORDER: #000000 1px line ; FONT-SIZE: 12; FONT-FAMILY: Arial; LEFT: 0px; COLOR: black; HEIGHT: 1 8px; BACKGROUND-COLOR: #cccccc">
  114. </center>
  115. </td>
  116. </tr><tr>
  117. <td>
  118. <center>
  119. <p><br>
  120. <input type="hidden" name="q" value="<?php echo $Qword[$randomNum] ?>">
  121. <input type="hidden" name="canswer" value="<?php echo $answer[$randomNum] ?>">
  122. <input type="hidden" name="asked" value="<?php echo $asked ?>">
  123. <input type="hidden" name="number" value="<?php echo $number ?>">
  124. <input type="hidden" name="correct" value="<?php echo $correct ?>">
  125. <input type="hidden" name="incorrect" value="<?php echo $incorrect ?>">
  126. <input type="submit" name="invullen" value="Invullen" size=10 style="BORDER: #000000 1px line ; COLOR: white; BACKGROUND-COLOR:#888888" >
  127. </center>
  128. </td>
  129. </tr>
  130. </table>
  131. </form>
  132. <script type="text/javascript">
  133. <!--
  134. document.unordened.fillin.focus();
  135. -->
  136. </script>
  137. </center>


Depending on how php is setup it may or may not add a backslash before any single quotes you have in your words when they are passed to the evalution form. If you want to prevent them from showing up onscreen when echoing them surround them with the stripslashes function (echo stripslashes($q) for example) It might be best to avoid the quotes entirely if you can.

Another potential problem is the use of special character like the umlaut (I think that's the correct name for the two little dots over a vowel anyway). Unless you are sure that your user will enter those character exactly as they are in your answer it might be best to avoid them.

If the script times out when running the full lists you may have to break it down into 4 or 5 quizzes of 20-25 words each, but I was able to run the full list of 115 without timing out, so I don't think it will.

Post Information

  • Total Posts in this topic: 18 posts
  • Users browsing this forum: No registered users and 80 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.