PHP word quiz using forms
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
Hi,
I tried to script something in PHP,
without the tables and the other stuff this is it:
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
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>
$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>
- <?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>
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
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
January 17th, 2004, 4:12 am
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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>
$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>
- <?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>
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
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?
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


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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.
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.
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
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 of evaluation:
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
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>
$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>
- <?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>
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
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
- <?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
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


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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.
I think that's it anyway.
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>
$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>
- <?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>
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
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
- <?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
I think that's it anyway.
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
Youre most thankful once again
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?
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


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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:
and for the second file you could add the following 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 .
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>
<input type="hidden" name="number" value="<? echo $number ?>">
</form>
<script type="text/javascript">
<!--
document.ordened.fillin.focus();
-->
</script>
- <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>
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>
<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>
- <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>
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 .
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
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:
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
But thats wrong, right?
If I do that, itll calculate again and probably come to another number.
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
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
__________________-
Evaluation
For displaying wrong/right, and calculating wrong/right.
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.
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;
}
?>">
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;
}
?>">
- <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;
- }
- ?>">
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;
?>
echo $q;
?>
- <?php
- echo $q;
- ?>
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;
}
?>
$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;
}
?>
- <?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;
- }
- ?>
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++;
?>
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++;
?>
- <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++;
- ?>
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 ?>">
<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" >
- <input type="hidden" name="number" value="<? echo $number ?>">
- <input type="hidden" name="correct" value="<? echo $correct ?>">
- <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++;
}
?>
if($fillin != $canswer){
// answer is incorrect
echo "Fout!";
$incorrect++;
} else {
// answer is correct
echo "Goed!";
$correct++;
}
?>
- <?php
- if($fillin != $canswer){
- // answer is incorrect
- echo "Fout!";
- $incorrect++;
- } else {
- // answer is correct
- echo "Goed!";
- $correct++;
- }
- ?>
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>
<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>
- <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>
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


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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.
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.
Free Programming Resources
- RichB
- Guru


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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
evaluation2.php
[code]
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>
$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>
- <?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>
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>
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>
- <?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>
[code]
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
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
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?
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
}
?>
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
}
?>
- <?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
- }
- ?>
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


- Joined: May 17, 2003
- Posts: 1121
- Loc: Boston
- Status: Offline
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().
Two other useful rounding functions are ceil() and floor().
Free Programming Resources
- Inito
- Graduate


- Joined: Dec 30, 2003
- Posts: 223
- Status: Offline
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
January 26th, 2004, 6:50 am
1, 2
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 18 posts
- Users browsing this forum: No registered users and 208 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
