Forum Moderators: coopster

Message Too Old, No Replies

Random Include

         

ran_dizolph

3:38 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



Hi there,
I'm working on a small script to display 1 of 4 include files at random (per refresh).

Here's the code i've got thus far;


<?php
$testimfiles = array (
'testimonials/testim_1.inc',
'testimonials/testim_2.inc',
'testimonials/testim_3.inc',
'testimonials/testim_4.inc'
)
include ($testimfiles[rand(0,3)]LIMIT 1) ;
?>

as of right now, it's giving me an 'unexpected T_INCLUDE' error. not sure where to go from here.

Thank you!

coopster

3:52 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A couple of problems here. First, you never terminated your array definition with a semicolon. Next, there is no LIMIT parameter in the rand() [php.net] function.
<?php 
$testimfiles = array (
'testimonials/testim_1.inc',
'testimonials/testim_2.inc',
'testimonials/testim_3.inc',
'testimonials/testim_4.inc'
);
include ($testimfiles[rand(0,3)]) ;
?>

ran_dizolph

4:14 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



perfect...thank you! i knew it had to be something simple like that.

jatar_k

5:34 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<?php include 'testimonials/testim_' . rand(0,3) . '.inc';?>