sorting fields within a record

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2012   (RSS)

By Deborah - June 16, 2012

I have an editor that allows for multiple numerical price options for a product listing. I need to compare the numbers of the various fields and display the lowest value of those fields on the list page.

(Fields only allow entry of numbers and decimal point.)
EXAMPLE:
field: price_option_01 = 10.00
field: price_option_02 = 6.00
field: price_option_03 = 8.00

The desired value returned on the page would be: 6.00

I don't know how to begin to do this or if it can be done, but am hoping someone might have such a method in their CMSB/PHP toolbox. And thanks in advance!

~ Deborah

Re: [Deborah] sorting fields within a record

By Jason - June 18, 2012

Hi Deborah,

You can try using the PHP min() function to get the lowest numerical value like this:

EXAMPLE:
$price = min($record['price_option_01'], $record['price_option_02'], $record['price_option_03']);

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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