Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8158263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:33:05+00:00 2026-06-06T17:33:05+00:00

What function is equal to mysql_num_rows in Magento?

  • 0

What function is equal to mysql_num_rows in Magento?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:33:07+00:00Added an answer on June 6, 2026 at 5:33 pm

    For Magento, the proper equivalent is PHP’s count() function.

    Why?

    Magento usually uses Varien_Data_Collection instances to fetch result sets containing multiple records. Varien implements the Lazy Load Pattern for these collections, that is, no result set will be fetched before you really need it.

    If you take a look at the Varien_Data_Collection class, you’ll see, that this class does implement PHP’s Countable interface and the proper count() method for this interface:

    class Varien_Data_Collection implements IteratorAggregate, Countable
    {
        :
        public function count()
        {
            $this->load();
            return count($this->_items);
        }
        :
    }
    

    If you’re asking yourself now, what got lazy loading to do with counting records, then you need to know that querying a collection the usual Magento way, e.g. like this:

    $collection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addFieldToFilter(
            'status',
            Mage_Catalog_Model_Product_Status::STATUS_ENABLED
        );
    

    does not fetch the result set at all. But, how do you count records of a result set which hasn’t been fetched yet? Right, you can’t. And neither can mysql_num_rows. It fetches the result set first.

    Now, when you call count() on the collection, e.g. by

    $n = count($collection);
    

    PHP’s core count() function will detect that the passed argument $collection implements a Countable interface and has its own count() method defined, so it will call that one.

    This leads to really fetching the result set* and storing it to $this->_items, which finally allows counting the records and return the number.


    * In Magento you can also call foreach ($collection as $product) to really fetch the result set, but that’s another story.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The numpy.equal function does not work if a list or array contains strings: >>>
From version to version of .NET the more function that's equal to P/Invoke is
like the function usort in php but if two members compare as equal, their
<script type=text/javascript> $(document).ready(function() { //select all the a tag with name equal to modal
What is the code for an equal function? This values in this column and
Since the equals function in array only check the instance, it doesn't work well
I want to write a function like equalp, which gives #t for (equalp Xy
Possible Duplicate: Java: Always override equals? should I override equals function for any class
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function checkuser(user) { var ret = false; $.ajax({ type:'POST', url:'user.php', async:false, data:{'user':user}, success:function (data)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.