Hi
I am writing a maths test which makes up "random" questions. As part of this I wish to choose a random .gif image (eg an equation obtained using the equation editor in MS Word.) from three stored images named in an array: $q6image=array("/q6_1image.gif","/q6_2image.gif","/q6_3image.gif");
The aim is to pass a random .gif image in this First program to Second program (via use of a form & PHP). Question 6 is a question, one of many questions, as part of the test. Below are relevant snippets of code. Skipping down to the end of this my basic question is why does the line:
echo "<img src=$q6image[1] >"; works, while the line below doesn't
echo "<img src=".$q6image[$_SESSION['value_of_q6rn']].">";
Any hints/suggestions, greatfully received.
David
First program:
//HTML interspersed with <? PHP ?>
$q6rn=rand(0,2); //gets a random number in range 0 to 2
$q6image=array("/q6_1image.gif","/q6_2image.gif","/q6_3image.gif");
$_SESSION['value_of_q6rn'] = $q6rn;
<!-- question 6 //-->
<tr>
<td colspan="2" >6. Simplify the expression: <img src=<? echo $q6image[$q6rn] ?> >
<br>
</td>
</tr>
Second program:
$q6image=array("../q6_1image.gif","../q6_2image.gif","../q6_3image.gif");
// Below works * * * * * * * * * * * * * * * * * * * * * * * * *
//echo "<img src=$q6image[1] >";
//Below doesn't work; $_SESSION['value_of_q6rn'] appears to have a NULL value
echo "<img src=".$q6image[$_SESSION['value_of_q6rn']].">";