mutiple choice calculations

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

mutiple choice calculations

Post by dandare »

hi there,

I was wondering if anyone had any ideas of how I can represent a correct answer asw a number which will be calculated and sent back via the feedback page

Code: Select all

echo "<p><input type=radio name=Q1 value=\"$aa\">$aa<br /> 
                <input type=radio name=Q1 value=\"$ab\">$ab<br /> 
	        <input type=radio name=Q1 value=\"$ac\">$ac<br /> 
	        <input type=radio name=Q1 value=\"$ad\">$ad<br /></p>";
Is it possible to use a condition such as:


Code: Select all

if($aa = $Q1) {
$Q1 == 1; 
}else{ 
$Q1 == 0;
or something similar?



Any feedback would be appreciated.
Thank you
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a switch.
dandare
Forum Commoner
Posts: 26
Joined: Wed Jul 26, 2006 7:56 am
Location: London

Post by dandare »

Hi Feyd

Thanks for you feedback. Just a little clarity (I think i worte my php out wrong).

By posting a form it reads the name and takes the value. As answer A ($aa) is the correct value should i say:

Code: Select all

switch ($Q1) {

case '$aa' : ==1;
break;

case '$ab' ==0;
etc..
sorry i'm kinda new to this
Post Reply