db_select based on userid: uid I have a dilemma i just can't figure out, and i need your help. The thing is, I wish to display the ip address of the logged in user in my custom form. The problem i have is how do i make it based on the logged in user? 

The following is the code i used: 


  $hostname = db_query("SELECT hostname FROM {accesslog} WHERE uid =
  :uid LIMIT 1', array(':uid' =>33));
  
  echo "Hostname:" . $hostname . "";
If you want the logged in user info, try the following (I have not tested, but it should work).

global $user;

$hostname = db_query("SELECT hostname FROM {accesslog} WHERE uid = :uid LIMIT 1', array(':uid' =&gt;$user-&gt;uid))-&gt;fetchField();


The global $user object will return information from the currently logged in user.  You might want to put some authentication in to check that the user is logged in if this is used in an area where anonymous users can visit.  Maybe wrap it in an if statement like I've done below:

if (user_is_logged_in() == TRUE) {

  global $user;

  $hostname = db_query("SELECT hostname FROM {accesslog} WHERE uid = :uid LIMIT 1", array(':uid' =&gt; $user-&gt;uid))-&gt;fetchField();

  echo 'Hostname: ' . $hostname;
}
else {
  echo 'You are not logged in.';
}