title: What is wrong with mysql_num_rows()?
body: <p>I have this code to get the user name that a friend has messaged to someone <em>like user to from message</em>.  <code>mysql_num_rows</code> is not working and my user names come up as unknown.  Does this have something to do with <code>mysql_num_rows()</code>?</p>
  
  <pre><code>function getusername($userid) {
      $sql = "SELECT username FROM user WHERE `id` = '".$userid."' LIMIT 1";
      $result = mysql_query($sql);
      // Check if there is someone with this id
      if(mysql_num_rows($result)) {
          // if yes get his username
          $row = mysql_fetch_row($result);
          return $row[0];
      } else {
          // if not, name him Unknown
          return "Unknown";
      }
  }
  </code></pre>