Drupal 7 – Get number of returned rows on db_query()

db_query() returns a DatabaseStatementInterface object which has a function for retrieving the number of returned rows in the last SQL statement.

You could use the following piece of code to get the total number of nodes in Drupal.

$num_of_nodes = db_query('SELECT nid FROM {node}')->rowCount(); 

 

Done =)

Reference:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.