Page 1 of 1

[PHP] Question

Posted: Tue 25. Oct 2005, 20:25
by d-lexy
Hi guys,

I need to integrate some PHP code into my templates. I need to define some variables in the beginning of the template and then apply these variables throughout the template. The problem is that when you close the [PHP] or open new one, I'm not sure - the value of the variable is lost.

Does anyone have any tips on how to avoid this?

Thanks in advance!

Posted: Tue 25. Oct 2005, 20:33
by frold
can you use:

[PHP]include ();[/PHP] ?

and then place the code in a new php file...?

Posted: Tue 25. Oct 2005, 20:39
by d-lexy
Hi Frold, thanks for your quick reply.

Unfortunately this won't work. Here is what I have.
In the beginning of the template I generate a random number from 1 to 3

Code: Select all

$option = rand(1,3)
Then in 2 different places I have to use the generated random number to display an image from 1.gif to 3.gif and in the second place include an HTML file from 1.html to 3.html

Thank you!

Posted: Wed 26. Oct 2005, 09:40
by cwenet
Hi,

perhaps try this:

first make your random number global

[PHP]
$_SESSION['MyRandom'] = rand(1,3);
[/PHP]

And than you can call it everywhere and everytime:

[PHP]
echo "<img src='".$_SESSION['MyRandom'].".jpg'>";
[/PHP]

Posted: Wed 26. Oct 2005, 14:49
by Neelix
Random + Image = ... :?:
d-lexy wrote: Then in 2 different places I have to use the generated random number to display an image from 1.gif to 3.gif and in the second place include an HTML file from 1.html to 3.html
Whats with RT {RANDOM:picture/1to3} using in your templates?
Save your 1..3.gif in an folder "1to3" and ready... (I hope)

Posted: Wed 26. Oct 2005, 16:07
by d-lexy
Neelix wrote:Random + Image = ... :?:
d-lexy wrote: Then in 2 different places I have to use the generated random number to display an image from 1.gif to 3.gif and in the second place include an HTML file from 1.html to 3.html
Whats with RT {RANDOM:picture/1to3} using in your templates?
Save your 1..3.gif in an folder "1to3" and ready... (I hope)
This won't work unfortunatelly, because I also have to include a random HTML file that corresponds to the random loaded image. So lets say random image is 2.gif then the include file has to be 2.html

Using sessions like cwenet recommended seems to make the most sence.
Thank you all for your input!