Total records

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 31, 2010   (RSS)

By keith_s - August 31, 2010

How do I determine the total number of records through the section viewer code? I am using a php random number generator function to pull a number at random within a certain range of numbers.

What I want to do is this:
The php function I'm using is:
$random = rand(1, 5);
... but as you can see, the 5 in this case has to be the max number of existing records. Therefore, I need to determine what the number of records is, in a variable, so that I can pass it to this function.

I think I use the getRecords function for CMS, but am not sure exactly how to do that (or if that is what I even need to use).

How do I get this "total records" value, OR if there is a simpler way to grab a record at random in the header code, how do I do that?

Thanks in advance,
Keith D Sellars

Re: [webgfx] Total records

By zip222 - August 31, 2010

<?php echo ($tablenameMetaData['totalRecords']); ?>

replace tablename with your tablename

Re: [zip222] Total records

By zip222 - August 31, 2010 - edited: August 31, 2010

wait, if you're just trying to display a random article, use the Code Generator and select the Random option. It will give you the necessary code. it will look like this:
list($tablenameRecords, $tablenameMetaData) = getRecords(array(
'tableName' => 'tablename',
'limit' => '1',
'orderBy' => 'RAND()',
));