Webmaster Forums 101 - Free Help and Discussions
 
 
 

MEMBER REWARDS - Earn free advertising by participating in these forums! Click here for details.

Welcome to Webmaster Forums 101!

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th November 2005, 01:01 AM   #1

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default 12 Times Table Quiz

This is being developed for use by students on their mobiles.
www.edufacts.info In Maths section.

/timetable1.php
2 random numbers are generated and displayed. Students inputs their answer, click submit.
/timetable2.php
Displays "Correct" else "Wrong answer, should be xx"

How can you send the two randomly generated numbers to the second .php file? I cannot see how you can use the Form. It errors any PHP inside <form></form>
Can it be done on one PHP page?
Can you input data directly into PHP rather than using <input> method.

/timetable1.php
<form method="get" enctype="multipart/form-data" action="http://www.dtscan.com/mobile/timestable2.php">
<?php
$n1 = rand (1, 12);
$n2 = rand (1, 12);

print "Multiply $n1 by $n2 <br />";
?>
What is your answer<br />
<input type="text" name="answer" size="2" />
<input type="submit" name="submit" value="Check Answer" />
</form>

/timetable2.php
<?php
$answer = $_GET['answer'];
$n1 = $_GET['an1'];
$n2 = $_GET['an2'];

$ans = $n1 * $n2;

if ($answer == $ans) {print "Correct Answer";}

else {print "Correct Answer is $ans";}
?>

You might notice that my PHP files are held on another server. I took me a day to find out my original server is not PHP enabled.
POST does not work on Mobile phones. Another day to discover that.

Tony Bell
techitout is offline   Reply With Quote
Old 4th November 2005, 08:01 AM   #2
Mr. Tech's Avatar

Username: Mr. Tech
Rank: Problem Solver
Join Date: Dec 2004
Location: Gold Coast, Australia
Posts: 2,166
Points: 1,025.61
Send a message via MSN to Mr. Tech
Default

Quote:
Originally Posted by techitout
Can you input data directly into PHP rather than using <input> method.

Yes you can... You can do it put using a session. Here is the code:

/timetable1.php
PHP Code:
<?php
session_start
();
     
$n1 rand (112);
     
$n2 rand (112);
$_SESSION['n1'] =      $n1;
$_SESSION['n2'] =      $n2;
?>
<form method="get" enctype="multipart/form-data" action="http://www.dtscan.com/mobile/timestable2.php">
<?php   
print "Multiply $n1 by $n2 <br />";
   
?>
      What is your answer<br />
          <input type="text" name="answer" size="2" />
       <input type="submit" name="submit" value="Check Answer" />
    </form>

/timetable2.php
PHP Code:
<?php
session_start
();
   
$answer $_GET['answer'];
   
$n1 $_SESSION['n1'];
   
$n2 $_SESSION['n2'];
 
   
$ans $n1 $n2;
 
   if (
$answer == $ans)    {print "Correct Answer";}
 
    else       {print 
"Correct Answer is $ans";}
 
?>

Hope that helps
__________________
Please read the Forum Rules

Get rewarded for posting
- free advertising!

.::. [ Webmaster Resources ] .::. [ Web Design ] .::. [ Developer Tutorials ] .::.
Mr. Tech is offline   Reply With Quote
Old 9th November 2005, 07:51 AM   #3

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default It Works

Thanks Mr Tech.
It worked first time. I then added some styling, OOPs, failed, went back to the begining and add bit by bit.
Amazing how much PHP I have picked up. I know the difference betwween ' and "
How does SESSIONS work? I understand how Forms transmits data, you can see it when you use GET.

Do you know of any Forums dealing with Mobiles, it's a can of worms.

Thanks again for this and my other posts.

Tony Bell
techitout is offline   Reply With Quote
Old 9th November 2005, 09:00 AM   #4
Mr. Tech's Avatar

Username: Mr. Tech
Rank: Problem Solver
Join Date: Dec 2004
Location: Gold Coast, Australia
Posts: 2,166
Points: 1,025.61
Send a message via MSN to Mr. Tech
Default

Glad it worked

Quote:
Originally Posted by techitout
How does SESSIONS work?

Basically the session is stored in a cookie and expires as soon as the visitor closes the browser window.

I can't say I do know of any forums dealing with mobiles. I suggest you try a Google search and see what you can find. I'm sure there will be plenty to choose from.
__________________
Please read the Forum Rules

Get rewarded for posting
- free advertising!

.::. [ Webmaster Resources ] .::. [ Web Design ] .::. [ Developer Tutorials ] .::.
Mr. Tech is offline   Reply With Quote
Old 18th November 2005, 10:01 PM   #5

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default

A special Educational Needs teacher looked at this programme, saw its potential and asked for scoring facilities. This raises a few problems.

Can Cookie's be used to retain the scoring values for the length of the quiz?
Can you use Cookie's and Sessions together?
Can you read a Cookie then send new values back on the same page?
Where must they placed on the page, I have seen reference to Buffering Output.?
I have had a go at writting code without must success. The additional logic I am using is:-

On Answer page "timestabl2.php"

Obtain $score and $total values from a Cookie
I assume initial values will be zero
If corect answer add 1 to both $score and $total
If incorrect add 1 to $total
Return these new values the Cookies (time-out set to 30mins)

Pupil return back to the Main Page using link to open up a new page so generating new random numbers. Not Back Button.

On Main Page "timestable1.php"

Read Cookie for $score and $total
Score displayed as a percentage with number of attempts.
Possible display time left!

I would be greatful for any help, I cannot find any info on tutor web pages etc.

Tony Bell
techitout is offline   Reply With Quote
Old 21st November 2005, 04:57 AM   #6

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default

This is how I re-wrote the code to add a scoring facility. It still works but does not score.

timestable1.php
<?php
session_start();

$n1 = rand (1, 12);
$n2 = rand (1, 12);

$_SESSION['n1'] = $n1;
$_SESSION['n2'] = $n2;
?>
<html>
<head>
<title>Times table on your Mobile</title>

<body style="margin: 0 5px; padding: 0; border: 0;text-align:center;
font-family:sans-serif;background-color:#ffffcc;">

<span style="color:red;font-size:medium;">Times Table</span>
<hr />

<?php
print "<span style='font-size:small; color:maroon;'>Multiply</span> $n1 <span style='font-size:small; color:maroon;'>by</span> $n2 <br />";
?>

<form method="get" enctype="multipart/form-data" action="http://www.dtscan.com/mobile/timestable2.php">

<span style="font-size:small; color:maroon;">

What is your answer<br />
<input type="text" name="answer" size="2" /><br />

<input type="submit" name="submit" value="Check Answer" />

<br />&nbsp;<br />
<hr />
<?php
$total = $_COOKIE['total'];
$score = $_COOKIE['score'];

if ($total == 0) {print ""; }

else {
$percent = $score/$total*100;

print "Your Score is $percent from $total Questions";
}
?>


<div style="text-align:center">
| <a href="http://www.edufacts.info/maths.html">Maths</a> |
</div>
</span>

</form>
</body>
</html>


timestable2.php
<?php

setcookie ('total',$total);
setcookie ('score',$score);


session_start();

$answer = $_GET['answer'];
$n1 = $_SESSION['n1'];
$n2 = $_SESSION['n2'];

$ans = $n1 * $n2;

if ($answer == $ans)
{
$score = $score + 1;
$total = $total + 1;


print "<hr />Correct Answer<hr /><a href='http://www.dtscan.com/mobile/timestable1.php'>Next Question</a>";
}
else
{
$total = $total + 1;
print "<hr />Wrong Answer<br />Correct answer is $ans<hr /><a href='http://www.dtscan.com/mobile/timestable1.php'>Next Question</a>";
}
?>
techitout is offline   Reply With Quote
Old 21st November 2005, 08:37 AM   #7

Username: techitout
Rank: WF101 Newbie
Join Date: Mar 2005
Posts: 17
Points: 0.00
Default

I had another go, this time I only used SESSION and it worked. The coding is not exactly as above, now all SESSIONS are at the top.

It seems illogical. You have to create SESSIONS at the begining of the page but it is taking variables from further on. I always thought that the script was read in a continous sequence from begining to end.
Another odd thing is that I have PHP - HTML - PHP scripts. PHP Variables can be manipulated across HTML code, it does not have to be one continous PHP script.

Now I have another problem to solve. The only way to reset the score is to close the browser. This might not even work in Opera as it Caches everthing. I thought that by going to another page the SESSION would terminate. I will have to add a "Reset" button.

Tony
techitout is offline   Reply With Quote
Old 21st November 2005, 10:24 AM   #8
Mr. Tech's Avatar

Username: Mr. Tech
Rank: Problem Solver
Join Date: Dec 2004
Location: Gold Coast, Australia
Posts: 2,166
Points: 1,025.61
Send a message via MSN to Mr. Tech
Default

Hey Tony,

Glad you figured it out. I'm not sure which of those questions you still need answered so please let me know.

If you are trying to destroy a session, have a look at this function:

http://au3.php.net/manual/en/functio...on-destroy.php
__________________
Please read the Forum Rules

Get rewarded for posting
- free advertising!

.::. [ Webmaster Resources ] .::. [ Web Design ] .::. [ Developer Tutorials ] .::.
Mr. Tech is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Login
User Name
Password


Featured Members


Featured Links


Useful Resources
Webmaster Resources
Developers Tools
Developer Tutorials


Partners

All times are GMT +10. The time now is 10:52 PM.


Powered by vBulletin Version 3.5.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.3.2
 
 
WEBMASTER FORUMS 101
ARCHIVE
CONTACT US
TOP
   
© Webmaster Forums 101 2005. All Rights Reserved.
Design by: vBCore