Miva Merchant Development by Scot's Scripts

MySQL COUNT: Get Total Number of Records Without Loading

Miva Random Code Trivia

Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)
SEO Audit & Inquiries • News & Updates • SEO for Miva Merchant

MySQL COUNT: Get Total Number of Records Without Loading

THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.

Scot Ranney • April 20, 2026 (updated: April 21, 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

mysql