Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A Little help with my , radio buttons and process
Old 01-12-2009, 03:59 PM A Little help with my , radio buttons and process
Average Talker

Posts: 15
Trades: 0
Hi chaps if you could help me out with this it would be great!

What I'm making is a quiz game and the problem i'm having is with echoing includes now I can do that fine but is echoing all of them?!?

what it is ment to do is if you get a question right or wrong it will display a fact about the answer chosen, that's what in the includes are for so you pick one answer from a radio button from the other page it parse the date to here, adjust lives and score(that works fine) then displays the info.

I have been messing around with the code for a few hours now and it gotta be something wrong with the structure?

thanks in advance Luke

PHP Code:
<?php
session_start
(); 
$answer $_POST['q1'];
$ans1 = include('ans/q1a1.php');
$ans2 = include('ans/q1a2.php');
$ans3 = include('ans/q1a3.php');
$ans4 = include('ans/q1a4.php');
$ans5 = include('ans/q1a5.php');
$ans6 = include('ans/q1a6.php');

if (
$answer == "answer4")
{ echo 
"$ans4"$_SESSION['score'] += 1;}

elseif(
$answer == "answer1")
{echo 
"$ans1"$_SESSION['lives'] -= 1;}

elseif(
$answer == "answer2")
{echo 
"$ans2"$_SESSION['lives'] -= 1;}

elseif(
$answer == "answer3")
{echo 
"$ans3"$_SESSION['lives'] -= 1;}

elseif(
$answer == "answer5")
{echo 
"$ans5"$_SESSION['lives'] -= 1;}

else(
$answer == "answer6")
{echo 
"$ans6"$_SESSION['lives'] -= 1;}

Print_r ($_SESSION);

session_destroy();
         
?>

Last edited by lukie_boy; 01-12-2009 at 04:42 PM..
lukie_boy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-12-2009, 05:23 PM Re: A Little help with my , radio buttons and process
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
Okay so are the answers just stored in a php file? Why don't you use a database. It's much faster that way.

But if you do want to just get contents off the .php file and not process it use file_get_contents() instead of include. If you use include() it will include the file. Period. And it will always do so even if you don't echo the variable.

An alternative way to do this would be to only include the file you need in the answer. There's really no reason to load info about all the answers if you are only displaying one of them.
PHP Code:
<?php
session_start
(); 
$answer $_POST['q1'];

if (
$answer == "answer4")
{
include(
'ans/q1a4.php');
echo 
$_SESSION['score'] += 1;
}

elseif(
$answer == "answer1")
{
include(
'ans/q1a1.php');
echo 
$_SESSION['score'] -= 1;
}

elseif(
$answer == "answer2")
{
include(
'ans/q1a2.php');
echo 
$_SESSION['score'] -= 1;
}
elseif(
$answer == "answer3")
{
include(
'ans/q1a3.php');
echo 
$_SESSION['score'] -= 1;
}
elseif(
$answer == "answer5")
{
include(
'ans/q1a5.php');
echo 
$_SESSION['score'] -= 1;
}
else(
$answer == "answer6")
{
include(
'ans/q1a6.php');
echo 
$_SESSION['score'] -= 1;
}
Print_r ($_SESSION);

session_destroy();
         
?>
I still think it would make your life easier to use a database though. Then you'd be able to control things a bit better and not have to worry about includes.
__________________
Freelance web+graphic designer and PHP developer.

Please login or register to view this content. Registration is FREE
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Old 01-12-2009, 05:33 PM Re: A Little help with my , radio buttons and process
Average Talker

Posts: 15
Trades: 0
Quote:
Okay so are the answers just stored in a php file? Why don't you use a database. It's much faster that way.
in the include() file are paragraphs of text and videos, so if you get it the question right wrong it will display some info about the answer you have picked, in this example "answer4" is correct.

I have just tried file_get_contents() and it works perfectly. I have never heard of that function before, is it more economical an the server also?

Thank you very much for your help also!
lukie_boy is offline
Reply With Quote
View Public Profile
 
Old 01-12-2009, 05:36 PM Re: A Little help with my , radio buttons and process
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
As long as you're not importing a huge file it shouldn't affect the server. Glad I could help =)
__________________
Freelance web+graphic designer and PHP developer.

Please login or register to view this content. Registration is FREE
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A Little help with my , radio buttons and process
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17206 seconds with 12 queries