I want to be able to kind of have the php and the xsl work together so the random question and answer can be generated, but I'm really not sure how to do this. So far this is what I have in my php:
And this is what I have in my xsl:PHP Code:<?php
$question_answer = array(
1=>array(
'question'=>'1+1',
'answer'=>2,
'text_answer' => 'two'
),
2=>array(
'question'=>'2+5',
'answer'=>7,
'text_answer' => 'seven'
),
3=>array(
'question'=>'3+1',
'answer'=>4,
'text_answer' => 'four'
),
);
if($_POST['submit']){
if ($_POST['answer'] == $question_answer[$_POST['question_answer_number']]['answer'] || $_POST['answer'] == $question_answer[$_POST['question_answer_number']]['text_answer']) {
echo 'You got the answer right.';
} else {
echo 'You guessed wrong.';
}
} else {
}
?>
Many thanks for any help.Code:<form method="post"> Question:<?php $rand = rand(1,3); echo $question_answer[$rand]['question']; ?><br /> <input type="hidden" value="<?php echo $rand; ?>" name="question_answer_number"/> <label for="answer">Answer:</label> <input name="answer" value="" /><br /> <input type="submit" name="guess" value="Guess" /> </form>



Reply With Quote
Bookmarks