[PHP] Question

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
d-lexy
Posts: 76
Joined: Fri 22. Oct 2004, 22:59
Location: Toronto, Canada / Tallinn, Estonia

[PHP] Question

Post 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!
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

can you use:

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

and then place the code in a new php file...?
http://www.studmed.dk Portal for doctors and medical students in Denmark
d-lexy
Posts: 76
Joined: Fri 22. Oct 2004, 22:59
Location: Toronto, Canada / Tallinn, Estonia

Post 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!
cwenet
Posts: 159
Joined: Sat 24. Jul 2004, 10:21
Location: Lake Of Constance, Germany

Post 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]
Neelix
Posts: 80
Joined: Wed 29. Sep 2004, 12:06
Location: España

Post 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)
Erfahrung ist das, was man besitzt, kurz nach dem es gebraucht wurde.
Warning: I have no foggiest idea of English/German, but I do
-ha{p}{p}y day/night/dia/noche-
d-lexy
Posts: 76
Joined: Fri 22. Oct 2004, 22:59
Location: Toronto, Canada / Tallinn, Estonia

Post 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!
Post Reply