chrismarsden Posted May 3, 2010 Share Posted May 3, 2010 Hi guys, not sure if this is possible or not cos im new to this but i was after some help in the right direction... basicly what i wanna do is have a site with testimonials on each page... i don't want them to be the same on each and want them to change on reload randomly... Eg - on index I have a testimonial from joe blogs - i go to about us and i have a testimonial from john doe - i go back to index and the testimonial has changed to king kong (ran out of anonymous names lol) what would you suggest to make this possible... the testimonials are located in an include. <?php include 'testimonials.php'; ?> <div class="main-subcontent"> <div class="subcontent-unit-border-orange"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="orange">header</h1> <p>testimonial here</p> </div> <div class="subcontent-unit-border-green"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="green">content</h1> <p>content </p> </div> </div> </div> Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 3, 2010 Share Posted May 3, 2010 [This has nothing to do with Regular Expressions. Moving to PHP forum] Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 3, 2010 Share Posted May 3, 2010 Exactly "HOW" are the testimonials stored in that file? I would suggest that in that include file you put the testimonials into an array and add a line to define a testimonial randomly. testimonials.php <?php $testimonials = array( "It's Great! - Robert Thomas", "Never leave home without it - Bob Johnson", "It's a piece of Crap. Don't buy it!!! - Mr. Negativity." ); $testimonial = $testimonials[array_rand($testimonials)]; ?> Then on the pages where you need a testimonial, include the file as you are now. Then in the content echo $testimonial where you need it: <div class="main-subcontent"> <div class="subcontent-unit-border-orange"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="orange">header</h1> <p><?php echo $testimonial; ?></p> </div> <div class="subcontent-unit-border-green"> <div class="round-border-topleft"></div><div class="round-border-topright"></div> <h1 class="green">content</h1> <p>content</p> </div> </div> Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 5, 2010 Author Share Posted May 5, 2010 thanks guys, i will give that a go now... Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 5, 2010 Author Share Posted May 5, 2010 it just gave me undefined variable errors... any ideas? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 6, 2010 Share Posted May 6, 2010 it just gave me undefined variable errors... any ideas? Well, it worked for me. I actually tested that code before I posted. Since you didn't take the time to post the actual error (with the line numbers) and the relevant code, there's nothing I can do to help. Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 6, 2010 Author Share Posted May 6, 2010 Hey, thanks for your help, it was me being thick!!! what i cant figure out tho is how to put an img and a href in to the script so that the testimonial shows an image and link... any ideas??? the code is below which im using for the testimonials: <?php $testimonials = array( "<h3>Mr Kibir Rahman T/A East India Trading Company</h3><P> 'Since opening our 5 restaurants you have really helped us.'<P>", "<h3>Steve Bird T/A 1 Stop Magic Carpets</h3><p>'I would like to thank your member of staff for helping me'<P> ", ); $testimonial = $testimonials[array_rand($testimonials)]; ?> testimonials are fake of course... real ones are yet to be added lol, what im basicly after is on the first one an img with a link to the webite of the company and a link to more testimonials page, on the second just a link to more testimonials. any ideas? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 6, 2010 Share Posted May 6, 2010 You can put whatever you want into the variables. Whatever you put in it will get used. If you know how to write the HTML code for an image, just include it into the testimonial string. The only thing to watch for is quotation marks. If you define a string with double quotation marks and you want to use double quotation marks in the string, you will need to escpe them (same goes for single quotation marks: $testimonials = array( "<h3><a href=\"http://www.eastindia.com\">Mr Kibir Rahman T/A East India Trading Company</a></h3> <img src=\"http://www.eastindia.com\logo.gif\"> <P>'Since opening our 5 restaurants you have really helped us.'<P>", "<h3>Steve Bird T/A 1 Stop Magic Carpets</h3><p>'I would like to thank your member of staff for helping me'<P> ", ); Quote Link to comment Share on other sites More sharing options...
chrismarsden Posted May 6, 2010 Author Share Posted May 6, 2010 Hey, thanks for the help, I figured out before if i use single quotation marks it works fine so all done... you have been a massive help! thank you!!! chris. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.