How do I get the uid of a node? I am trying to get the user ID associated with a node using this code in Drupal 7, without any luck:

$uid =  $node-&gt;uid;
echo "uid: " . $uid;


$uid doesn't have any value in it.

I want to get it so that I can count the number of my members' posts. 

$node = node_load('NID');
$uid = $node-&gt;uid;
$sql = "SELECT nid FROM {node} WHERE uid = $uid";
$result = db_query($sql);

$number_of_rows = $result-&gt;rowCount();
echo "uid: " . $uid;
print "&lt;p&gt;$node-&gt;name has submitted &lt;em&gt;&lt;strong&gt;$number_of_rows&lt;/strong&gt;&lt;/em&gt; source code / articles.&lt;/p&gt;";'


I tried putting it in a display suite module under fields. I also tried putting in a page content type.
That should work. Try making sure that you have a properly loaded node object.

$node = node_load('NID');
echo $node-&gt;uid;


It is possible that if the node was created by an anonymous user that the $uid would be zero and thus wouldn't print.