Web Hosting Talk







View Full Version : Rotating Text


Kemik
08-20-2006, 07:23 PM
Hello all,

I want to put my testimonials on in my header.php. However, it would be nice for them to be in a random order. E.g. When you refresh a page it will show a different testimonial.

Does anyone know if there is an easy and neat way of doing this using PHP?

Thanks.

Sohan
08-20-2006, 08:03 PM
if you dont have too many:

<?php

$t[0] = "1st one";
$t[1] = "2nd one";
$t[2] = "3rd one";

$rand = rand (0, 2);
echo "$t[$rand]";

?>

If you have more, use MySQL.

If you have loads, it will make huge file loads with the one above. If you have more than 10 large ones, use MySQL.

Kemik
08-20-2006, 08:12 PM
Thanks mate, works great :D

ezbnc
08-21-2006, 11:44 AM
You can try this also works great from what I have noticed

<?
$files = glob('[insert path to a folder you've created for random files]/*');
include $files[array_rand($files)];
?>

Mr.Muffinman
08-21-2006, 12:05 PM
<?php
$items = array(
"item1",
"item3",
"item3",
"item4",
);

$random = array_rand($items);

echo $items[$random];
?>


This is just an alternative. As Sohan said, If you have a large list of items, it is better if you use MySQL.