Miva Merchant Development by Scot's Scripts

MySQL COUNT: Get Total Number of Records Without Loading

Miva Knowledge Base
MySQL COUNT: Get Total Number of Records Without Loading
Important Notice: This information is for internal reference only. Use at your own risk.
Does Google actually understand your Miva Merchant store? Our JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

MySQL COUNT: Get Total Number of Records Without Loading

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>

https://www.scotsscripts.com/mvblog/mysql-total-get-total-number-of-records-without-loading.html

mvkb_mysql