views:

164

answers:

3

I'd like to show a simple testimonial rotator on my site done in php.

Php can take testimonials from either a Text file or db, but I don't understand how to create te rotator part.

I'd appreciate any help you can offer. Thanks.

A: 

you can use the order by rand() to select random records and show them or if u want to show them sequentially , keep track of the ids shown and then when u reach the end start from first record.

Sabeen Malik
+4  A: 

To get it out of a DB, you'd do something like this in SQL:

SELECT testimonial FROM testimonials ORDER BY RAND() LIMIT 1

To get it out of a text file, you'd do something like this:

// load the file's contents
$testimonials = file_get_contents('text_file.txt');
// split the list by new lines, i.e. one testimonial per line
$testimonials = explode("\n", $testimonials);
// print a random one
print $testimonials[rand(0, (count($testimonials) - 1)];
ceejayoz
+1  A: 

If you want them to update live, you would have to use javascript or a framework such as jQuery. Otherwise @ceejayoz has provided a perfect answer.

Jamie
Right, I'd probably use a content slider than this to rotate testimonials with some fade/slide effect. Thanks!
Nimbuz