How to count the number of post by author in D7? I am using the following code in drupal 6 but now this code does not work with Drupal 7.

&lt;?php
$uid=$node-&gt;uid;
$results=db_query("select COUNT(nid) AS count from node where uid=$uid");

while ($res = db_fetch_object($results)) {
print "&lt;p&gt;" . $node-&gt;name . " has submitted &lt;em&gt;&lt;strong&gt;" . $res-&gt;count . "&lt;/strong&gt;&lt;/em&gt;          source code / articles.&lt;/p&gt;";
}
?&gt;


My primary problem is on how to query the number of post like the sql statement above as:

db_query("select COUNT(nid) AS count from node where uid=$uid");

Anyone know the equivalent to this on D7?

BTW, I want to use the code in display suite module.
The result of db_query() should now be iterated over directly, db_fetch_object() isn't part of Drupal 7. 

You could also make use of the fetchField() method to get the result of your COUNT query:

$uid = $node-&gt;uid;
$args = array(':uid' =&gt; $uid);
$count = db_query('SELECT COUNT(nid) FROM {node} WHERE uid = :uid', $args)-&gt;fetchField();

print "&lt;p&gt;$node-&gt;name has submitted &lt;em&gt;&lt;strong&gt;$count&lt;/strong&gt;&lt;/em&gt; source code / articles.&lt;/p&gt;";


The above example uses the preferred method of passing arguments to a database query, it's safer than including them directly in the query string.

If you did want to loop over the results (for a query with more than one row/field) you'd do it like this:

$result = db_query('SELECT * FROM {node}');
foreach ($result as $row) {
  $nid = $row-&gt;nid;
}