Show the highest number
6 posts by 3 authors in: Forums > CMS Builder
Last Post: February 11, 2015 (RSS)
By richo - February 10, 2015
I am trying to help a school display the House with the most house points at the end of each week.
There are 5 houses. How can I show the house with the highest points please?
Any help would be appreciated.
Many thanks
John
By Damon - February 10, 2015
Hi John,
Assuming you have a "Points" field in CMS Builder for each House, you can have the Houses sorted by the highest to lowest by using the the Sort order in the CMS Builder admin or add it directly into the frontend template.
Sort in CMS Builder:
Go to Admin > Section Editors > Houses.
Click on the Sorting tab and add points+0 DESC
This will sort the Houses by Points, highest to lowest in both the CMS Builder admin and the published frontend page.
You can also do a custom sort just on the publish page if you don't want the CMS Builder admin sorted in the same way. To do this, add the orderBy code to your page:
'orderBy' => 'points+0 DESC',
More details here:
http://www.interactivetools.com/docs/cmsbuilder/viewer_options.html
Hope this helps!
Damon Edis - interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
By richo - February 10, 2015
Thanks for the reply. I guess I should read more!
I have also been trying to put:
The leaders are "House name" with "points score" points.
Help with this would be appreciated thank you.
John
Try something like this if you want just the top leader: (You will need to substitute your variables for table and field names)
<?php // load the top points records assuming you only want the top leader
list($houseRecords, $houseMetaData) = getRecords(array(
'tableName' => 'house', // or whatever the table name is
'orderBy' => 'points+0 DESC' // bring highest points to top
'limit' => '1',
'allowSearch' => false,
));
$topRecord = @$houseRecords[0]; // get first record only
?>
<div class="some-wrapper">
The leaders are <?php echo $topRecord['name'] ?> with <?php echo $topRecord['name'] ?> points.
</div>
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
Happy to help!
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987