Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 if string conditional
bekti Offline
Junior Member
**
Posts: 43
Joined: Mar 2012
Post: #1
if string conditional
can we put some random code?

Code:
1
2
3
4
5
6
<if rand(1,2)>
$1 = {string1}
$2 = {string2}
</if>

it will be random,if not string 1 then string 2 will show up...

08-29-2012 01:14 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: if string conditional

Code:
<if mt_rand(0,1) then>
string 1
<else>
string 2
</if>


My Blog
08-29-2012 03:25 PM
Find all posts by this user Quote this message in a reply
bekti Offline
Junior Member
**
Posts: 43
Joined: Mar 2012
Post: #3
RE: if string conditional
how about more than 2 string?

Code:
1
2
3
4
5
6
7
<if mt_rand(0,2) then>
string 1
<elseif  mt_rand(0,2) then>
string 2
<elseif  mt_rand(0,2) then>
string 3
</if>


like that? but it doesn't work

(This post was last modified: 08-29-2012 04:39 PM by bekti.)
08-29-2012 03:57 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: if string conditional

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>


My Blog
08-29-2012 04:51 PM
Find all posts by this user Quote this message in a reply
bekti Offline
Junior Member
**
Posts: 43
Joined: Mar 2012
Post: #5
RE: if string conditional
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>

don't work

i mean not text 1,2,3..but string like this

<setvar r>array('{string1}', '{string2}', '{string3}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>

i use this one but it doesn't work
08-29-2012 07:08 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #6
RE: if string conditional
(08-29-2012 07:08 PM)bekti Wrote:  i mean not text 1,2,3..but string like this
Text 1, Text 2, Text 3 are strings.

08-30-2012 01:11 AM
Find all posts by this user Quote this message in a reply
bekti Offline
Junior Member
**
Posts: 43
Joined: Mar 2012
Post: #7
RE: if string conditional

Code:
<setvar r>array('{string1}', '{string2}', '{string3}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>



but when i try to set

Code:
<setvar r>array('{myadvertisements[zone_1]}', '{myadvertisements[zone_2]}', '{myadvertisements[zone_3]}')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])?>



it's appear an error..my header template doesn't show up...

any fix?

08-30-2012 01:21 AM
Find all posts by this user Quote this message in a reply
leefish Offline
Hamster
*****
Posts: 1,009
Joined: Apr 2010
Post: #8
RE: if string conditional
This code works for me :

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])]?>


I added a ] at the end of the second line right before the ?



[Image: leelink.gif]
MYBB1.6 & XThreads
08-30-2012 01:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
bekti Offline
Junior Member
**
Posts: 43
Joined: Mar 2012
Post: #9
RE: if string conditional
(08-30-2012 01:36 AM)leefish Wrote:  This code works for me :

Code:
<setvar r>array('text 1', 'text 2', 'text 3')</setvar>
<?=$GLOBALS['tplvars']['r'][array_rand($GLOBALS['tplvars']['r'])]?>


I added a ] at the end of the second line right before the ?


work like a charm...thank leefish
08-30-2012 02:02 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: