Jump to content

scdas

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Everything posted by scdas

  1. You need something like this, embedded in your HTML: <? //starts PHP $asterisks="***************"; $no_of_stairs=10; for( i from 1 to $no_of_stairs) { echo substring($asterisks,$i); } ?> // ends PHP The above won't work, but it will get you started. I suggest you concentrate on the above as a PHP file: paste it into a text editor and save it as, say stairs.php in your cgi-bin folder. (I'm assuming you have a website capable of PHP.) Check out keywords (eg for, substring) in the PHP manual: http://www.php.net/manual/en/ to get the code working Cheers scdas Im trying to create a loop to display a set of asterisks to create a set of "stairs." example: * ** *** **** ***** ****** ******* Im not very good at html and everything Ive tried has failed. Does anyone have any suggestions or samples? Thanks a lot, i REALLY appreciate any help at all!
  2. FYI Got it to work - the problem appears to be that the array variable won't take a subscripted varaiable. Here is my workaround. $temp=$_SESSION['value_of_q6rn']; //echo $tab4."<img src=$q6image[$_SESSION['value_of_q6rn']] >"; NB Won't accept variable subscript echo $tab4."<img src=$q6image[$temp] >"; Cheers David
  3. Thanks for the advice re the 'session_start();' code, but I already had that in both programs. Any other suggestions?
  4. 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']].">";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.