Ok, so I'm developing a block that only shows when viewing a user's profile.

If it's the users' own profile, it says "You have...." and runs a query based upon that user's users.uid field

If someone is viewing another user's profile, it will say " has..." and run a query based upon the viewed profile's users.uid field.

I can load a logged in user's users.uid field, but how do I get the field of the user who's profile is being viewed?

thanks!

Comments

nevets’s picture

When view a users profile the path is of the form user/#, where # is a number. You can get each of the parts of the path with the arg() function. In this case arg(0) is 'user' and arg(1) is the user id. So in code you could use

<?php
  $uid = arg(1);
?>

Note the code assumes it is looking at a path of the form user/# which is ok if you restrict the block to only show for pages of that type.