min()/max()

Time again for another little known/used CF function. This is one I actually missed for quite some time as well. Min/Max work like so - given two values, the min will return the lessor of the two while max will return the higher value.

Ok, sounds a bit pointless, but it actually comes in handy in quite a few places where you would normally probably use a cfif statement. Consider your typical Next N interface. Normally you show N records per page. Your cfloop (or cfoutput) would use an endrow value which needs to be equal to either the current starting position plus N, or the max number of rows. If the starting position plus N is greater than the max number of rows, then you only want to go up to query.recordCount. Here is a great place to use min(), you could simply do: endrow=”#min(myQuery.recordCount,url.start+perPage)#”.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments