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:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s