Random Content

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 7, 2009   (RSS)

Re: [Moonworks] Random Content

By Damon - July 7, 2009

Hi,

Here are some steps and code for you:

Create a section for "Quotes" - Multi Record.

Add a field for the "Quote" - choose textbox.
Add a field for "Quoter" - choose textfield.

Here is some example code to output the quote and quoter randomly:

<?php
require_once "/yourpath/to/the/viewer_functions.php";
list($quotesRecords, $quotesMetaData) = getRecords(array(
'tableName' => 'quotes',
'limit' => '1',
'orderBy' => 'RAND()',
'allowSearch' => '0',
));
?>

<?php foreach ($quotesRecords as $record): ?>
Quote: <?php echo $record['quote'] ?><br/>
Quoter: <strong><?php echo $record['quoter'] ?></strong><br/>
<?php endforeach; ?>


This will randomly output one quote. Add this code to the top of each of your pages or add it using an include.

Hope that helps. :)
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Random Content

By Moonworks - July 7, 2009

Thanks for that

The problem I get with it, is the following error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/vhosts/moonworksuk.com/subdomains/blackhound/httpdocs/quote.php on line 12
High quality residential training for writers, actors &amp; Film Making - Click Here for further information

Re: [Moonworks] Random Content

By Moonworks - July 7, 2009

It's ok, I just had to remove the require_once "/var/www/vhosts....... line, due to it being an include.

Thanks for the help, and making it so simple [cool]
High quality residential training for writers, actors &amp; Film Making - Click Here for further information