Counting Rows in Joomla

  • PDF

Counting Rows

Like all coding there are a few ways you can count the number of rows in a SQL query.  Two ways are counting in the query using SQL or using the getNumRows() method in Joomla.

SQL Method

"SELECT count * " . " FROM #__attendee_attenders" . " WHERE username = '" . $uid . "'";

The result set is the number of rows.  (Query might have to be written as "count(*)" depending on SQL preferences on your server.)

Joomla Method

Another alternative is to use the Joomla Database methods.  So say you want to check the number of rows returned use these Joomla Database methods

$num_rows = $db->getNumRows();
$result = $db->loadRowList();

How to Choose

If you are only looking at the number of rows then calculate the number of rows in the query, this will be faster.  If however, you are going to be performing additional computations on the dataset the use the Joomla database methods for checking the number of rows.