Scot Ranney • April 20, 2026
Nifty MySQL trick to load a total without loading/reading all the records.
This example is from the blogger and includes a condition to get totals based on an ID, nothing special, just copied it out of the module code.
<MvFUNCTION NAME = "messages_total" PARAMETERS = "blog_id" STANDARDOUTPUTLEVEL=""> <MvIF EXPR = "{ l.blog_id }"> <MvOPENVIEW NAME = "Merchant" VIEW = "messages" QUERY = "{ 'SELECT COUNT( * ) AS item_count FROM ' $ g.smr_table_prefix $ 'MESSAGES WHERE blog_id = ?' }" FIELDS = "l.blog_id"> <MvELSE> <MvOPENVIEW NAME = "Merchant" VIEW = "messages" QUERY = "{ 'SELECT COUNT( * ) AS item_count FROM ' $ g.smr_table_prefix $ 'MESSAGES ' }"> </MvIF> <MvASSIGN NAME = "l.total" VALUE = "{ int( messages.d.item_count ) }"> <MvCLOSEVIEW NAME = "Merchant" VIEW = "messages"> <MvFUNCRETURN VALUE = "{ l.total }"> </MvFUNCTION>
mvkb_mysql