--- /Users/timothybolton/Downloads/node_limitnumber/node_limitnumber.module
+++ node_limitnumber.module
@@ -67,16 +67,16 @@
   if (module_exists('og')) {
     $count = count($settings['og']);
     $limit_reached = FALSE;
-    if (isset($node->og_groups)) {
+    if (isset($user->og_groups)) {
       foreach ($settings['og'] as $gid => $value) {
         // Loop through each of the og settings to find enabled
         if ($value != 0) {
-          foreach ($node->og_groups as $node_gid) {
-            // Loop through each of the groups for the node to see if they match
-            if ($value == $node_gid) {
+          foreach ($user->og_groups as $user_gid) {
+            // Loop through each of the groups for the user to see if they match
+            if ($value == $user_gid['nid']) {
               // The node matches the group with the limit
               // Find all nodes that have been created for that group
-              $q = "SELECT * FROM {node} INNER JOIN {og_ancestry} ON node.nid=og_ancestry.nid WHERE og_ancestry.group_nid = %d";
+              $q = "SELECT * FROM {node} INNER JOIN {og_ancestry} ON {node}.nid={og_ancestry}.nid WHERE {og_ancestry}.group_nid = %d";
               $result = db_query($q, $gid);
               $num = db_affected_rows();
               if ($num >= $settings['limit']) {// We have the data, now we check the limit
@@ -160,12 +160,13 @@
     ),
   );
   if (module_exists('og')) {
-    $q = "SELECT nid,og_description FROM {og}";
+    $q = "SELECT nid, og_description FROM {og}";
     $result = db_query($q);
     while ($data = db_fetch_array($result)) {
       $node = node_load($data['nid']);
       $groups[$node->nid] = $node->title;
     }
+
     $form['settings']['og'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Limit By Organic Group'),
